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 | |
Darin Petkov | 60ceaf3 | 2012-10-18 10:36:01 +0200 | [diff] [blame] | 17 | #include <base/file_util.h> |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 18 | #include <base/memory/ref_counted.h> |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 19 | #include <base/memory/scoped_ptr.h> |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 20 | #include <base/stringprintf.h> |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 21 | #include <base/string_number_conversions.h> |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 22 | #include <base/string_split.h> |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 23 | #include <base/string_util.h> |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 24 | #include <chromeos/dbus/service_constants.h> |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 25 | #include <dbus-c++/dbus.h> |
Chris Masone | 7156c92 | 2011-08-23 20:36:21 -0700 | [diff] [blame] | 26 | #include <gmock/gmock.h> |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 27 | #include <gtest/gtest.h> |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 28 | |
| 29 | #include "shill/dbus_adaptor.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 30 | #include "shill/event_dispatcher.h" |
Gaurav Shah | 6d2c72d | 2012-10-16 16:30:44 -0700 | [diff] [blame] | 31 | #include "shill/geolocation_info.h" |
mukesh agrawal | 8ede052 | 2011-10-03 14:57:44 -0700 | [diff] [blame] | 32 | #include "shill/ieee80211.h" |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 33 | #include "shill/key_value_store.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 34 | #include "shill/logging.h" |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 35 | #include "shill/manager.h" |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 36 | #include "shill/mock_dbus_manager.h" |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 37 | #include "shill/mock_device.h" |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 38 | #include "shill/mock_device_info.h" |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 39 | #include "shill/mock_dhcp_config.h" |
| 40 | #include "shill/mock_dhcp_provider.h" |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 41 | #include "shill/mock_event_dispatcher.h" |
Paul Stewart | 3c508e1 | 2012-08-09 11:40:06 -0700 | [diff] [blame] | 42 | #include "shill/mock_link_monitor.h" |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 43 | #include "shill/mock_log.h" |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 44 | #include "shill/mock_manager.h" |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 45 | #include "shill/mock_metrics.h" |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 46 | #include "shill/mock_profile.h" |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 47 | #include "shill/mock_rtnl_handler.h" |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 48 | #include "shill/mock_store.h" |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 49 | #include "shill/mock_supplicant_bss_proxy.h" |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 50 | #include "shill/mock_supplicant_interface_proxy.h" |
| 51 | #include "shill/mock_supplicant_process_proxy.h" |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 52 | #include "shill/mock_time.h" |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 53 | #include "shill/mock_wifi_service.h" |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 54 | #include "shill/nice_mock_control.h" |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 55 | #include "shill/property_store_inspector.h" |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 56 | #include "shill/property_store_unittest.h" |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 57 | #include "shill/proxy_factory.h" |
| 58 | #include "shill/wifi_endpoint.h" |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 59 | #include "shill/wifi_service.h" |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 60 | #include "shill/wpa_supplicant.h" |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 61 | |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 62 | |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 63 | using std::map; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 64 | using std::set; |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 65 | using std::string; |
| 66 | using std::vector; |
| 67 | using ::testing::_; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 68 | using ::testing::AnyNumber; |
| 69 | using ::testing::DefaultValue; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 70 | using ::testing::DoAll; |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 71 | using ::testing::EndsWith; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 72 | using ::testing::InSequence; |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 73 | using ::testing::Invoke; |
Paul Stewart | 549d44c | 2012-07-03 12:40:25 -0700 | [diff] [blame] | 74 | using ::testing::InvokeWithoutArgs; |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 75 | using ::testing::Mock; |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 76 | using ::testing::NiceMock; |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 77 | using ::testing::Return; |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 78 | using ::testing::SaveArg; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 79 | using ::testing::SetArgumentPointee; |
| 80 | using ::testing::StrEq; |
| 81 | using ::testing::StrictMock; |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 82 | using ::testing::Test; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 83 | using ::testing::Throw; |
mukesh agrawal | 8ede052 | 2011-10-03 14:57:44 -0700 | [diff] [blame] | 84 | using ::testing::Values; |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 85 | |
| 86 | namespace shill { |
| 87 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 88 | class WiFiPropertyTest : public PropertyStoreTest { |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 89 | public: |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 90 | WiFiPropertyTest() |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 91 | : device_(new WiFi(control_interface(), |
| 92 | NULL, NULL, NULL, "wifi", "", 0)) { |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 93 | } |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 94 | virtual ~WiFiPropertyTest() {} |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 95 | |
| 96 | protected: |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 97 | WiFiRefPtr device_; |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 100 | TEST_F(WiFiPropertyTest, Contains) { |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 101 | EXPECT_TRUE(device_->store().Contains(flimflam::kNameProperty)); |
| 102 | EXPECT_FALSE(device_->store().Contains("")); |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 103 | } |
| 104 | |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 105 | TEST_F(WiFiPropertyTest, SetProperty) { |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 106 | { |
| 107 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 108 | EXPECT_TRUE(DBusAdaptor::SetProperty( |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 109 | device_->mutable_store(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 110 | flimflam::kBgscanSignalThresholdProperty, |
| 111 | PropertyStoreTest::kInt32V, |
| 112 | &error)); |
| 113 | } |
| 114 | { |
| 115 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 116 | EXPECT_TRUE(DBusAdaptor::SetProperty(device_->mutable_store(), |
| 117 | flimflam::kScanIntervalProperty, |
| 118 | PropertyStoreTest::kUint16V, |
| 119 | &error)); |
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 | // 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] | 122 | { |
| 123 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 124 | EXPECT_FALSE(DBusAdaptor::SetProperty(device_->mutable_store(), |
| 125 | flimflam::kScanningProperty, |
| 126 | PropertyStoreTest::kBoolV, |
| 127 | &error)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 128 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 129 | } |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 130 | |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 131 | { |
| 132 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 133 | EXPECT_TRUE(DBusAdaptor::SetProperty( |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 134 | device_->mutable_store(), |
| 135 | flimflam::kBgscanMethodProperty, |
| 136 | DBusAdaptor::StringToVariant( |
| 137 | wpa_supplicant::kNetworkBgscanMethodSimple), |
| 138 | &error)); |
| 139 | } |
| 140 | |
| 141 | { |
| 142 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 143 | EXPECT_FALSE(DBusAdaptor::SetProperty( |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 144 | device_->mutable_store(), |
| 145 | flimflam::kBgscanMethodProperty, |
| 146 | DBusAdaptor::StringToVariant("not a real scan method"), |
| 147 | &error)); |
| 148 | } |
| 149 | } |
| 150 | |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 151 | TEST_F(WiFiPropertyTest, BgscanMethodProperty) { |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 152 | EXPECT_NE(wpa_supplicant::kNetworkBgscanMethodLearn, |
| 153 | WiFi::kDefaultBgscanMethod); |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 154 | EXPECT_TRUE(device_->bgscan_method_.empty()); |
| 155 | |
| 156 | string method; |
| 157 | PropertyStoreInspector inspector(&device_->store()); |
| 158 | EXPECT_TRUE(inspector.GetStringProperty(flimflam::kBgscanMethodProperty, |
| 159 | &method)); |
| 160 | EXPECT_EQ(WiFi::kDefaultBgscanMethod, method); |
| 161 | EXPECT_EQ(wpa_supplicant::kNetworkBgscanMethodSimple, method); |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 162 | |
| 163 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 164 | EXPECT_TRUE(DBusAdaptor::SetProperty( |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 165 | device_->mutable_store(), |
| 166 | flimflam::kBgscanMethodProperty, |
| 167 | DBusAdaptor::StringToVariant( |
| 168 | wpa_supplicant::kNetworkBgscanMethodLearn), |
| 169 | &error)); |
| 170 | EXPECT_EQ(wpa_supplicant::kNetworkBgscanMethodLearn, device_->bgscan_method_); |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 171 | EXPECT_TRUE(inspector.GetStringProperty(flimflam::kBgscanMethodProperty, |
| 172 | &method)); |
| 173 | EXPECT_EQ(wpa_supplicant::kNetworkBgscanMethodLearn, method); |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 174 | |
| 175 | EXPECT_TRUE(DBusAdaptor::ClearProperty( |
| 176 | device_->mutable_store(), flimflam::kBgscanMethodProperty, &error)); |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 177 | EXPECT_TRUE(inspector.GetStringProperty(flimflam::kBgscanMethodProperty, |
| 178 | &method)); |
| 179 | EXPECT_EQ(WiFi::kDefaultBgscanMethod, method); |
| 180 | EXPECT_TRUE(device_->bgscan_method_.empty()); |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 181 | } |
| 182 | |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 183 | class WiFiObjectTest : public ::testing::TestWithParam<string> { |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 184 | public: |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 185 | WiFiObjectTest(EventDispatcher *dispatcher) |
| 186 | : event_dispatcher_(dispatcher), |
| 187 | manager_(&control_interface_, NULL, &metrics_, &glib_), |
| 188 | device_info_(&control_interface_, dispatcher, &metrics_, &manager_), |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 189 | wifi_(new WiFi(&control_interface_, |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 190 | dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 191 | &metrics_, |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 192 | &manager_, |
| 193 | kDeviceName, |
| 194 | kDeviceAddress, |
| 195 | 0)), |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 196 | supplicant_process_proxy_(new NiceMock<MockSupplicantProcessProxy>()), |
| 197 | supplicant_interface_proxy_( |
| 198 | new NiceMock<MockSupplicantInterfaceProxy>(wifi_)), |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 199 | supplicant_bss_proxy_( |
| 200 | new NiceMock<MockSupplicantBSSProxy>()), |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 201 | dhcp_config_(new MockDHCPConfig(&control_interface_, |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 202 | kDeviceName)), |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 203 | dbus_manager_(new NiceMock<MockDBusManager>()), |
mukesh agrawal | 2f9df4e | 2012-08-08 12:29:20 -0700 | [diff] [blame] | 204 | proxy_factory_(this) { |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 205 | ::testing::DefaultValue< ::DBus::Path>::Set("/default/path"); |
mukesh agrawal | 4eb4d78 | 2011-12-05 17:34:37 +0000 | [diff] [blame] | 206 | // Except for WiFiServices created via WiFi::GetService, we expect |
| 207 | // that any WiFiService has been registered with the Manager. So |
| 208 | // default Manager.HasService to true, to make the common case |
| 209 | // easy. |
| 210 | ON_CALL(manager_, HasService(_)). |
| 211 | WillByDefault(Return(true)); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 212 | |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 213 | ON_CALL(dhcp_provider_, CreateConfig(_, _, _, _)). |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 214 | WillByDefault(Return(dhcp_config_)); |
| 215 | ON_CALL(*dhcp_config_.get(), RequestIP()). |
| 216 | WillByDefault(Return(true)); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 217 | |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 218 | manager_.dbus_manager_.reset(dbus_manager_); // Transfers ownership. |
| 219 | |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 220 | wifi_->time_ = &time_; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 221 | } |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 222 | |
| 223 | virtual void SetUp() { |
mukesh agrawal | 3ab56ac | 2012-05-31 14:41:43 -0700 | [diff] [blame] | 224 | // EnableScopes... so that we can EXPECT_CALL for scoped log messages. |
| 225 | ScopeLogger::GetInstance()->EnableScopesByName("wifi"); |
Christopher Wiley | d34a47c | 2012-08-01 15:42:45 -0700 | [diff] [blame] | 226 | ScopeLogger::GetInstance()->set_verbose_level(3); |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 227 | wifi_->proxy_factory_ = &proxy_factory_; |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 228 | static_cast<Device *>(wifi_)->rtnl_handler_ = &rtnl_handler_; |
| 229 | wifi_->set_dhcp_provider(&dhcp_provider_); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 230 | ON_CALL(manager_, device_info()). |
| 231 | WillByDefault(Return(&device_info_)); |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 232 | EXPECT_CALL(manager_, UpdateEnabledTechnologies()).Times(AnyNumber()); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 233 | EXPECT_CALL(manager_, DeregisterService(_)).Times(AnyNumber()); |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 234 | EXPECT_CALL(*supplicant_bss_proxy_, Die()).Times(AnyNumber()); |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | virtual void TearDown() { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 238 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 239 | wifi_->SelectService(NULL); |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 240 | if (supplicant_bss_proxy_.get()) { |
| 241 | EXPECT_CALL(*supplicant_bss_proxy_, Die()); |
| 242 | } |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 243 | wifi_->proxy_factory_ = NULL; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 244 | // must Stop WiFi instance, to clear its list of services. |
| 245 | // otherwise, the WiFi instance will not be deleted. (because |
| 246 | // services reference a WiFi instance, creating a cycle.) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 247 | wifi_->Stop(NULL, ResultCallback()); |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 248 | wifi_->set_dhcp_provider(NULL); |
mukesh agrawal | 3ab56ac | 2012-05-31 14:41:43 -0700 | [diff] [blame] | 249 | // Reset scope logging, to avoid interfering with other tests. |
| 250 | ScopeLogger::GetInstance()->EnableScopesByName("-wifi"); |
Christopher Wiley | d34a47c | 2012-08-01 15:42:45 -0700 | [diff] [blame] | 251 | ScopeLogger::GetInstance()->set_verbose_level(0); |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Paul Stewart | 549d44c | 2012-07-03 12:40:25 -0700 | [diff] [blame] | 254 | // Needs to be public since it is called via Invoke(). |
| 255 | void StopWiFi() { |
Paul Stewart | 549d44c | 2012-07-03 12:40:25 -0700 | [diff] [blame] | 256 | wifi_->SetEnabled(false); // Stop(NULL, ResultCallback()); |
| 257 | } |
| 258 | |
Christopher Wiley | c618448 | 2012-10-24 15:31:56 -0700 | [diff] [blame] | 259 | // Needs to be public since it is called via Invoke(). |
| 260 | void ThrowDBusError() { |
| 261 | throw DBus::Error("SomeDBusType", "A handy message"); |
| 262 | } |
| 263 | |
Paul Stewart | 549d44c | 2012-07-03 12:40:25 -0700 | [diff] [blame] | 264 | void UnloadService(const ServiceRefPtr &service) { |
| 265 | service->Unload(); |
| 266 | } |
| 267 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 268 | protected: |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 269 | typedef scoped_refptr<MockWiFiService> MockWiFiServiceRefPtr; |
| 270 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 271 | class TestProxyFactory : public ProxyFactory { |
| 272 | public: |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 273 | explicit TestProxyFactory(WiFiObjectTest *test); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 274 | |
| 275 | virtual SupplicantProcessProxyInterface *CreateSupplicantProcessProxy( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 276 | const char */*dbus_path*/, const char */*dbus_addr*/) { |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 277 | return test_->supplicant_process_proxy_.release(); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | virtual SupplicantInterfaceProxyInterface *CreateSupplicantInterfaceProxy( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 281 | const WiFiRefPtr &/*wifi*/, |
| 282 | const DBus::Path &/*object_path*/, |
| 283 | const char */*dbus_addr*/) { |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 284 | return test_->supplicant_interface_proxy_.release(); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 285 | } |
| 286 | |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 287 | MOCK_METHOD3(CreateSupplicantBSSProxy, |
| 288 | SupplicantBSSProxyInterface *( |
| 289 | WiFiEndpoint *wifi_endpoint, |
| 290 | const DBus::Path &object_path, |
| 291 | const char *dbus_addr)); |
| 292 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 293 | private: |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 294 | SupplicantBSSProxyInterface *CreateSupplicantBSSProxyInternal( |
| 295 | WiFiEndpoint */*wifi_endpoint*/, |
| 296 | const DBus::Path &/*object_path*/, |
| 297 | const char */*dbus_addr*/) { |
| 298 | return test_->supplicant_bss_proxy_.release(); |
| 299 | } |
| 300 | |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 301 | WiFiObjectTest *test_; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 302 | }; |
| 303 | |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 304 | void CancelScanTimer() { |
| 305 | wifi_->scan_timer_callback_.Cancel(); |
| 306 | } |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 307 | WiFiServiceRefPtr CreateServiceForEndpoint(const WiFiEndpoint &endpoint) { |
| 308 | bool hidden_ssid = false; |
| 309 | return wifi_->CreateServiceForEndpoint(endpoint, hidden_ssid); |
| 310 | } |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 311 | void FireScanTimer() { |
| 312 | wifi_->ScanTimerHandler(); |
| 313 | } |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 314 | const WiFiServiceRefPtr &GetCurrentService() { |
| 315 | return wifi_->current_service_; |
| 316 | } |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 317 | void SetCurrentService(const WiFiServiceRefPtr &service) { |
| 318 | wifi_->current_service_ = service; |
| 319 | } |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 320 | const WiFi::EndpointMap &GetEndpointMap() { |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 321 | return wifi_->endpoint_by_rpcid_; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 322 | } |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 323 | const WiFiServiceRefPtr &GetPendingService() { |
| 324 | return wifi_->pending_service_; |
| 325 | } |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 326 | const base::CancelableClosure &GetPendingTimeout() { |
| 327 | return wifi_->pending_timeout_callback_; |
| 328 | } |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 329 | const base::CancelableClosure &GetReconnectTimeoutCallback() { |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 330 | return wifi_->reconnect_timeout_callback_; |
| 331 | } |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 332 | int GetReconnectTimeoutSeconds() { |
| 333 | return WiFi::kReconnectTimeoutSeconds; |
| 334 | } |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 335 | const base::CancelableClosure &GetScanTimer() { |
| 336 | return wifi_->scan_timer_callback_; |
| 337 | } |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 338 | const vector<WiFiServiceRefPtr> &GetServices() { |
| 339 | return wifi_->services_; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 340 | } |
| 341 | // note: the tests need the proxies referenced by WiFi (not the |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 342 | // proxies instantiated by WiFiObjectTest), to ensure that WiFi |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 343 | // sets up its proxies correctly. |
| 344 | SupplicantProcessProxyInterface *GetSupplicantProcessProxy() { |
| 345 | return wifi_->supplicant_process_proxy_.get(); |
| 346 | } |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 347 | MockSupplicantInterfaceProxy *GetSupplicantInterfaceProxy() { |
| 348 | return dynamic_cast<MockSupplicantInterfaceProxy *>( |
| 349 | wifi_->supplicant_interface_proxy_.get()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 350 | } |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 351 | const string &GetSupplicantState() { |
| 352 | return wifi_->supplicant_state_; |
| 353 | } |
| 354 | void InitiateConnect(WiFiServiceRefPtr service) { |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 355 | map<string, ::DBus::Variant> params; |
| 356 | wifi_->ConnectTo(service, params); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 357 | } |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 358 | void InitiateDisconnect(WiFiServiceRefPtr service) { |
| 359 | wifi_->DisconnectFrom(service); |
| 360 | } |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 361 | WiFiEndpointRefPtr MakeEndpoint(const string &ssid, const string &bssid) { |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 362 | return WiFiEndpoint::MakeOpenEndpoint( |
| 363 | &proxy_factory_, NULL, ssid, bssid, 0, 0); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 364 | } |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 365 | MockWiFiServiceRefPtr MakeMockService(const std::string &security) { |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 366 | vector<uint8_t> ssid(1, 'a'); |
| 367 | return new MockWiFiService( |
| 368 | &control_interface_, |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 369 | event_dispatcher_, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 370 | &metrics_, |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 371 | &manager_, |
| 372 | wifi_, |
| 373 | ssid, |
| 374 | flimflam::kModeManaged, |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 375 | security, |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 376 | false); |
| 377 | } |
Ben Chan | 381fdcc | 2012-10-14 21:10:36 -0700 | [diff] [blame] | 378 | bool RemoveNetwork(const ::DBus::Path &network) { |
| 379 | return wifi_->RemoveNetwork(network); |
| 380 | } |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 381 | void RemoveBSS(const ::DBus::Path &bss_path); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 382 | void ReportBSS(const ::DBus::Path &bss_path, |
| 383 | const string &ssid, |
| 384 | const string &bssid, |
| 385 | int16_t signal_strength, |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 386 | uint16 frequency, |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 387 | const char *mode); |
Paul Stewart | 66c8600 | 2012-01-30 18:00:52 -0800 | [diff] [blame] | 388 | void ClearCachedCredentials() { |
| 389 | wifi_->ClearCachedCredentials(); |
| 390 | } |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 391 | void ReportIPConfigComplete() { |
Darin Petkov | 79d74c9 | 2012-03-07 17:20:32 +0100 | [diff] [blame] | 392 | wifi_->OnIPConfigUpdated(dhcp_config_, true); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 393 | } |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 394 | void ReportLinkUp() { |
| 395 | wifi_->LinkEvent(IFF_LOWER_UP, IFF_LOWER_UP); |
| 396 | } |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 397 | void ReportScanDone() { |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 398 | wifi_->ScanDoneTask(); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 399 | } |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 400 | void ReportCurrentBSSChanged(const string &new_bss) { |
| 401 | wifi_->CurrentBSSChanged(new_bss); |
| 402 | } |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 403 | void ReportStateChanged(const string &new_state) { |
| 404 | wifi_->StateChanged(new_state); |
| 405 | } |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 406 | void SetPendingService(const WiFiServiceRefPtr &service) { |
| 407 | wifi_->pending_service_ = service; |
| 408 | } |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 409 | void SetScanInterval(uint16_t interval_seconds) { |
| 410 | wifi_->SetScanInterval(interval_seconds, NULL); |
| 411 | } |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 412 | uint16_t GetScanInterval() { |
| 413 | return wifi_->GetScanInterval(NULL); |
| 414 | } |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 415 | void StartWiFi(bool supplicant_present) { |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 416 | wifi_->supplicant_present_ = supplicant_present; |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 417 | wifi_->SetEnabled(true); // Start(NULL, ResultCallback()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 418 | } |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 419 | void StartWiFi() { |
| 420 | StartWiFi(true); |
| 421 | } |
mukesh agrawal | 2f9df4e | 2012-08-08 12:29:20 -0700 | [diff] [blame] | 422 | void OnAfterResume() { |
| 423 | wifi_->OnAfterResume(); |
| 424 | } |
| 425 | void OnBeforeSuspend() { |
| 426 | wifi_->OnBeforeSuspend(); |
| 427 | } |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 428 | void OnSupplicantAppear() { |
| 429 | wifi_->OnSupplicantAppear(":1.7"); |
| 430 | EXPECT_TRUE(wifi_->supplicant_present_); |
| 431 | } |
| 432 | void OnSupplicantVanish() { |
| 433 | wifi_->OnSupplicantVanish(); |
| 434 | EXPECT_FALSE(wifi_->supplicant_present_); |
| 435 | } |
| 436 | bool GetSupplicantPresent() { |
| 437 | return wifi_->supplicant_present_; |
| 438 | } |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 439 | WiFiServiceRefPtr GetOpenService(const char *service_type, |
| 440 | const char *ssid, |
| 441 | const char *mode, |
| 442 | Error *result) { |
| 443 | return GetServiceInner(service_type, ssid, mode, NULL, NULL, false, result); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 444 | } |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 445 | WiFiServiceRefPtr GetService(const char *service_type, |
| 446 | const char *ssid, |
| 447 | const char *mode, |
| 448 | const char *security, |
| 449 | const char *passphrase, |
| 450 | Error *result) { |
| 451 | return GetServiceInner(service_type, ssid, mode, security, passphrase, |
| 452 | false, result); |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 453 | } |
| 454 | WiFiServiceRefPtr GetServiceInner(const char *service_type, |
| 455 | const char *ssid, |
| 456 | const char *mode, |
| 457 | const char *security, |
| 458 | const char *passphrase, |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 459 | bool allow_hidden, |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 460 | Error *result) { |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 461 | map<string, ::DBus::Variant> args; |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 462 | // in general, we want to avoid D-Bus specific code for any RPCs |
| 463 | // that come in via adaptors. we make an exception here, because |
| 464 | // calls to GetWifiService are rerouted from the Manager object to |
| 465 | // the Wifi class. |
| 466 | if (service_type != NULL) |
| 467 | args[flimflam::kTypeProperty].writer().append_string(service_type); |
| 468 | if (ssid != NULL) |
| 469 | args[flimflam::kSSIDProperty].writer().append_string(ssid); |
| 470 | if (mode != NULL) |
| 471 | args[flimflam::kModeProperty].writer().append_string(mode); |
| 472 | if (security != NULL) |
| 473 | args[flimflam::kSecurityProperty].writer().append_string(security); |
| 474 | if (passphrase != NULL) |
| 475 | args[flimflam::kPassphraseProperty].writer().append_string(passphrase); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 476 | if (!allow_hidden) |
| 477 | args[flimflam::kWifiHiddenSsid].writer().append_bool(false); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 478 | |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 479 | Error e; |
| 480 | KeyValueStore args_kv; |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 481 | DBusAdaptor::ArgsToKeyValueStore(args, &args_kv, &e); |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 482 | return wifi_->GetService(args_kv, result); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 483 | } |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 484 | |
| 485 | WiFiServiceRefPtr GetServiceWithKeyValues(const KeyValueStore &args, |
| 486 | Error *result) { |
| 487 | return wifi_->GetService(args, result); |
| 488 | } |
| 489 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 490 | WiFiServiceRefPtr FindService(const vector<uint8_t> &ssid, |
| 491 | const string &mode, |
| 492 | const string &security) { |
| 493 | return wifi_->FindService(ssid, mode, security); |
| 494 | } |
| 495 | bool LoadHiddenServices(StoreInterface *storage) { |
| 496 | return wifi_->LoadHiddenServices(storage); |
| 497 | } |
| 498 | void SetupHiddenStorage(MockStore *storage, const string &ssid, string *id) { |
| 499 | const string hex_ssid = base::HexEncode(ssid.data(), ssid.size()); |
| 500 | *id = StringToLowerASCII(base::StringPrintf("%s_%s_%s_%s_%s", |
| 501 | flimflam::kTypeWifi, |
| 502 | kDeviceAddress, |
| 503 | hex_ssid.c_str(), |
| 504 | flimflam::kModeManaged, |
| 505 | flimflam::kSecurityNone)); |
| 506 | const char *groups[] = { id->c_str() }; |
| 507 | EXPECT_CALL(*storage, GetGroupsWithKey(flimflam::kWifiHiddenSsid)) |
| 508 | .WillRepeatedly(Return(set<string>(groups, groups + 1))); |
| 509 | EXPECT_CALL(*storage, GetBool(StrEq(*id), flimflam::kWifiHiddenSsid, _)) |
| 510 | .WillRepeatedly(DoAll(SetArgumentPointee<2>(true), Return(true))); |
| 511 | EXPECT_CALL(*storage, GetString(StrEq(*id), flimflam::kSSIDProperty, _)) |
| 512 | .WillRepeatedly(DoAll(SetArgumentPointee<2>(hex_ssid), Return(true))); |
| 513 | } |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 514 | |
Paul Stewart | 549d44c | 2012-07-03 12:40:25 -0700 | [diff] [blame] | 515 | WiFiService *SetupConnectedService(const DBus::Path &network_path) { |
| 516 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
| 517 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _, _, _)).Times(AnyNumber()); |
| 518 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(AnyNumber()); |
| 519 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
| 520 | if (!network_path.empty()) { |
| 521 | EXPECT_CALL(*supplicant_interface_proxy_, AddNetwork(_)) |
| 522 | .WillOnce(Return(network_path)); |
| 523 | } |
| 524 | |
| 525 | StartWiFi(); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 526 | ReportBSS(kBSSName, kSSIDName, "00:00:00:00:00:00", 0, 0, |
| 527 | kNetworkModeAdHoc); |
Paul Stewart | 549d44c | 2012-07-03 12:40:25 -0700 | [diff] [blame] | 528 | WiFiService *service(GetServices().begin()->get()); |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 529 | EXPECT_TRUE(GetPendingTimeout().IsCancelled()); |
Paul Stewart | 549d44c | 2012-07-03 12:40:25 -0700 | [diff] [blame] | 530 | InitiateConnect(service); |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 531 | EXPECT_FALSE(GetPendingTimeout().IsCancelled()); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 532 | ReportCurrentBSSChanged(kBSSName); |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 533 | EXPECT_TRUE(GetPendingTimeout().IsCancelled()); |
Paul Stewart | 549d44c | 2012-07-03 12:40:25 -0700 | [diff] [blame] | 534 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 535 | |
| 536 | EXPECT_EQ(service, GetCurrentService()); |
| 537 | |
| 538 | return service; |
| 539 | } |
| 540 | |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 541 | bool SetBgscanMethod(const string &method) { |
| 542 | ::DBus::Error error; |
| 543 | return DBusAdaptor::SetProperty( |
| 544 | wifi_->mutable_store(), |
| 545 | flimflam::kBgscanMethodProperty, |
| 546 | DBusAdaptor::StringToVariant(method), |
| 547 | &error); |
| 548 | } |
| 549 | |
| 550 | void AppendBgscan(WiFiService *service, |
| 551 | std::map<std::string, DBus::Variant> *service_params) { |
| 552 | wifi_->AppendBgscan(service, service_params); |
| 553 | } |
| 554 | |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 555 | void ReportCertification(const map<string, ::DBus::Variant> &properties) { |
| 556 | wifi_->CertificationTask(properties); |
| 557 | } |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 558 | |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 559 | void RestartFastScanAttempts() { |
| 560 | wifi_->RestartFastScanAttempts(); |
| 561 | } |
| 562 | |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 563 | void StartReconnectTimer() { |
| 564 | wifi_->StartReconnectTimer(); |
| 565 | } |
| 566 | |
| 567 | void StopReconnectTimer() { |
| 568 | wifi_->StopReconnectTimer(); |
| 569 | } |
| 570 | |
Paul Stewart | 3c508e1 | 2012-08-09 11:40:06 -0700 | [diff] [blame] | 571 | void SetLinkMonitor(LinkMonitor *link_monitor) { |
| 572 | wifi_->set_link_monitor(link_monitor); |
| 573 | } |
| 574 | |
| 575 | void OnLinkMonitorFailure() { |
| 576 | wifi_->OnLinkMonitorFailure(); |
| 577 | } |
| 578 | |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 579 | NiceMockControl *control_interface() { |
| 580 | return &control_interface_; |
| 581 | } |
| 582 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 583 | MockManager *manager() { |
| 584 | return &manager_; |
| 585 | } |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 586 | |
| 587 | MockDeviceInfo *device_info() { |
| 588 | return &device_info_; |
| 589 | } |
| 590 | |
| 591 | MockDHCPProvider *dhcp_provider() { |
| 592 | return &dhcp_provider_; |
| 593 | } |
| 594 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 595 | const WiFiConstRefPtr wifi() const { |
| 596 | return wifi_; |
| 597 | } |
| 598 | |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 599 | TestProxyFactory *proxy_factory() { |
| 600 | return &proxy_factory_; |
| 601 | } |
| 602 | |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 603 | EventDispatcher *event_dispatcher_; |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 604 | NiceMock<MockRTNLHandler> rtnl_handler_; |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 605 | MockTime time_; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 606 | |
| 607 | private: |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 608 | NiceMockControl control_interface_; |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 609 | MockMetrics metrics_; |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 610 | MockGLib glib_; |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 611 | MockManager manager_; |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 612 | MockDeviceInfo device_info_; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 613 | WiFiRefPtr wifi_; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 614 | |
| 615 | // protected fields interspersed between private fields, due to |
| 616 | // initialization order |
| 617 | protected: |
| 618 | static const char kDeviceName[]; |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 619 | static const char kDeviceAddress[]; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 620 | static const char kNetworkModeAdHoc[]; |
| 621 | static const char kNetworkModeInfrastructure[]; |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 622 | static const char kBSSName[]; |
| 623 | static const char kSSIDName[]; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 624 | |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 625 | scoped_ptr<MockSupplicantProcessProxy> supplicant_process_proxy_; |
| 626 | scoped_ptr<MockSupplicantInterfaceProxy> supplicant_interface_proxy_; |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 627 | scoped_ptr<MockSupplicantBSSProxy> supplicant_bss_proxy_; |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 628 | MockDHCPProvider dhcp_provider_; |
| 629 | scoped_refptr<MockDHCPConfig> dhcp_config_; |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 630 | NiceMock<MockDBusManager> *dbus_manager_; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 631 | |
| 632 | private: |
| 633 | TestProxyFactory proxy_factory_; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 634 | }; |
| 635 | |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 636 | const char WiFiObjectTest::kDeviceName[] = "wlan0"; |
| 637 | const char WiFiObjectTest::kDeviceAddress[] = "000102030405"; |
| 638 | const char WiFiObjectTest::kNetworkModeAdHoc[] = "ad-hoc"; |
| 639 | const char WiFiObjectTest::kNetworkModeInfrastructure[] = "infrastructure"; |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 640 | const char WiFiObjectTest::kBSSName[] = "bss0"; |
| 641 | const char WiFiObjectTest::kSSIDName[] = "ssid0"; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 642 | |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 643 | void WiFiObjectTest::RemoveBSS(const ::DBus::Path &bss_path) { |
mukesh agrawal | b4bc57d | 2011-12-07 01:07:47 +0000 | [diff] [blame] | 644 | wifi_->BSSRemovedTask(bss_path); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 645 | } |
| 646 | |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 647 | void WiFiObjectTest::ReportBSS(const ::DBus::Path &bss_path, |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 648 | const string &ssid, |
| 649 | const string &bssid, |
| 650 | int16_t signal_strength, |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 651 | uint16 frequency, |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 652 | const char *mode) { |
| 653 | map<string, ::DBus::Variant> bss_properties; |
| 654 | |
| 655 | { |
| 656 | DBus::MessageIter writer(bss_properties["SSID"].writer()); |
| 657 | writer << vector<uint8_t>(ssid.begin(), ssid.end()); |
| 658 | } |
| 659 | { |
| 660 | string bssid_nosep; |
| 661 | vector<uint8_t> bssid_bytes; |
| 662 | RemoveChars(bssid, ":", &bssid_nosep); |
| 663 | base::HexStringToBytes(bssid_nosep, &bssid_bytes); |
| 664 | |
| 665 | DBus::MessageIter writer(bss_properties["BSSID"].writer()); |
| 666 | writer << bssid_bytes; |
| 667 | } |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 668 | bss_properties[wpa_supplicant::kBSSPropertySignal].writer(). |
| 669 | append_int16(signal_strength); |
| 670 | bss_properties[wpa_supplicant::kBSSPropertyFrequency].writer(). |
| 671 | append_uint16(frequency); |
| 672 | bss_properties[wpa_supplicant::kBSSPropertyMode].writer().append_string(mode); |
mukesh agrawal | b4bc57d | 2011-12-07 01:07:47 +0000 | [diff] [blame] | 673 | wifi_->BSSAddedTask(bss_path, bss_properties); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 676 | WiFiObjectTest::TestProxyFactory::TestProxyFactory(WiFiObjectTest *test) |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 677 | : test_(test) { |
| 678 | EXPECT_CALL(*this, CreateSupplicantBSSProxy(_, _, _)).Times(AnyNumber()); |
| 679 | ON_CALL(*this, CreateSupplicantBSSProxy(_, _, _)) |
| 680 | .WillByDefault( |
| 681 | Invoke(this, (&TestProxyFactory::CreateSupplicantBSSProxyInternal))); |
| 682 | } |
| 683 | |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 684 | // Most of our tests involve using a real EventDispatcher object. |
| 685 | class WiFiMainTest : public WiFiObjectTest { |
| 686 | public: |
| 687 | WiFiMainTest() : WiFiObjectTest(&dispatcher_) {} |
| 688 | |
| 689 | protected: |
| 690 | EventDispatcher dispatcher_; |
| 691 | }; |
| 692 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 693 | TEST_F(WiFiMainTest, ProxiesSetUpDuringStart) { |
| 694 | EXPECT_TRUE(GetSupplicantProcessProxy() == NULL); |
| 695 | EXPECT_TRUE(GetSupplicantInterfaceProxy() == NULL); |
| 696 | |
| 697 | StartWiFi(); |
| 698 | EXPECT_FALSE(GetSupplicantProcessProxy() == NULL); |
| 699 | EXPECT_FALSE(GetSupplicantInterfaceProxy() == NULL); |
| 700 | } |
| 701 | |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 702 | TEST_F(WiFiMainTest, SupplicantPresent) { |
| 703 | EXPECT_FALSE(GetSupplicantPresent()); |
| 704 | } |
| 705 | |
| 706 | TEST_F(WiFiMainTest, OnSupplicantAppearStarted) { |
| 707 | EXPECT_TRUE(GetSupplicantProcessProxy() == NULL); |
| 708 | |
| 709 | EXPECT_CALL(*dbus_manager_, WatchName(wpa_supplicant::kDBusAddr, _, _)); |
| 710 | StartWiFi(false); // No supplicant present. |
| 711 | EXPECT_TRUE(GetSupplicantProcessProxy() == NULL); |
| 712 | |
| 713 | OnSupplicantAppear(); |
| 714 | EXPECT_FALSE(GetSupplicantProcessProxy() == NULL); |
Darin Petkov | 9cd7ca1 | 2012-07-03 11:06:40 +0200 | [diff] [blame] | 715 | |
| 716 | // If supplicant reappears while the device is started, the device should be |
| 717 | // restarted. |
| 718 | EXPECT_CALL(*manager(), DeregisterDevice(_)); |
| 719 | EXPECT_CALL(*manager(), RegisterDevice(_)); |
| 720 | OnSupplicantAppear(); |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | TEST_F(WiFiMainTest, OnSupplicantAppearStopped) { |
| 724 | EXPECT_TRUE(GetSupplicantProcessProxy() == NULL); |
| 725 | |
| 726 | OnSupplicantAppear(); |
| 727 | EXPECT_TRUE(GetSupplicantProcessProxy() == NULL); |
Darin Petkov | 9cd7ca1 | 2012-07-03 11:06:40 +0200 | [diff] [blame] | 728 | |
| 729 | // If supplicant reappears while the device is stopped, the device should not |
| 730 | // be restarted. |
| 731 | EXPECT_CALL(*manager(), DeregisterDevice(_)).Times(0); |
| 732 | OnSupplicantAppear(); |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | TEST_F(WiFiMainTest, OnSupplicantVanishStarted) { |
| 736 | EXPECT_TRUE(GetSupplicantProcessProxy() == NULL); |
| 737 | |
| 738 | StartWiFi(); |
| 739 | EXPECT_FALSE(GetSupplicantProcessProxy() == NULL); |
| 740 | EXPECT_TRUE(GetSupplicantPresent()); |
| 741 | |
| 742 | EXPECT_CALL(*manager(), DeregisterDevice(_)); |
| 743 | EXPECT_CALL(*manager(), RegisterDevice(_)); |
| 744 | OnSupplicantVanish(); |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | TEST_F(WiFiMainTest, OnSupplicantVanishStopped) { |
| 748 | OnSupplicantAppear(); |
| 749 | EXPECT_TRUE(GetSupplicantPresent()); |
| 750 | EXPECT_CALL(*manager(), DeregisterDevice(_)).Times(0); |
| 751 | OnSupplicantVanish(); |
| 752 | } |
| 753 | |
Paul Stewart | 549d44c | 2012-07-03 12:40:25 -0700 | [diff] [blame] | 754 | TEST_F(WiFiMainTest, OnSupplicantVanishedWhileConnected) { |
| 755 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 756 | *supplicant_interface_proxy_; |
| 757 | WiFiService *service(SetupConnectedService(DBus::Path())); |
| 758 | ScopedMockLog log; |
| 759 | EXPECT_CALL(log, Log(_, _, _)).Times(AnyNumber()); |
Christopher Wiley | c618448 | 2012-10-24 15:31:56 -0700 | [diff] [blame] | 760 | EXPECT_CALL(log, Log(logging::LOG_ERROR, _, |
Paul Stewart | 549d44c | 2012-07-03 12:40:25 -0700 | [diff] [blame] | 761 | EndsWith("silently resetting current_service_."))); |
| 762 | EXPECT_CALL(*manager(), DeregisterDevice(_)) |
| 763 | .WillOnce(InvokeWithoutArgs(this, &WiFiObjectTest::StopWiFi)); |
| 764 | EXPECT_CALL(*manager(), DeregisterService(ServiceRefPtr(service))) |
| 765 | .WillOnce(Invoke(this, &WiFiObjectTest::UnloadService)); |
| 766 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()).Times(0); |
| 767 | EXPECT_CALL(*manager(), RegisterDevice(_)); |
| 768 | OnSupplicantVanish(); |
| 769 | EXPECT_TRUE(GetCurrentService() == NULL); |
| 770 | } |
| 771 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 772 | TEST_F(WiFiMainTest, CleanStart) { |
| 773 | EXPECT_CALL(*supplicant_process_proxy_, CreateInterface(_)); |
| 774 | EXPECT_CALL(*supplicant_process_proxy_, GetInterface(_)) |
| 775 | .Times(AnyNumber()) |
| 776 | .WillRepeatedly(Throw( |
| 777 | DBus::Error( |
| 778 | "fi.w1.wpa_supplicant1.InterfaceUnknown", |
| 779 | "test threw fi.w1.wpa_supplicant1.InterfaceUnknown"))); |
Paul Stewart | 87a4ae8 | 2012-10-26 15:49:32 -0700 | [diff] [blame] | 780 | EXPECT_CALL(*manager(), LoadDeviceFromProfiles(_)); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 781 | EXPECT_CALL(*supplicant_interface_proxy_, Scan(_)); |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 782 | EXPECT_TRUE(GetScanTimer().IsCancelled()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 783 | StartWiFi(); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 784 | dispatcher_.DispatchPendingEvents(); |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 785 | EXPECT_FALSE(GetScanTimer().IsCancelled()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 786 | } |
| 787 | |
Ben Chan | 381fdcc | 2012-10-14 21:10:36 -0700 | [diff] [blame] | 788 | TEST_F(WiFiMainTest, RemoveNetwork) { |
| 789 | DBus::Path network = "/test/path"; |
| 790 | EXPECT_CALL(*supplicant_interface_proxy_, RemoveNetwork(network)); |
| 791 | StartWiFi(); |
| 792 | EXPECT_TRUE(RemoveNetwork(network)); |
| 793 | } |
| 794 | |
| 795 | TEST_F(WiFiMainTest, RemoveNetworkWhenSupplicantReturnsNetworkUnknown) { |
| 796 | DBus::Path network = "/test/path"; |
| 797 | EXPECT_CALL(*supplicant_interface_proxy_, RemoveNetwork(network)) |
| 798 | .WillRepeatedly(Throw( |
| 799 | DBus::Error( |
| 800 | "fi.w1.wpa_supplicant1.NetworkUnknown", |
| 801 | "test threw fi.w1.wpa_supplicant1.NetworkUnknown"))); |
| 802 | StartWiFi(); |
| 803 | EXPECT_TRUE(RemoveNetwork(network)); |
| 804 | } |
| 805 | |
| 806 | TEST_F(WiFiMainTest, RemoveNetworkWhenSupplicantReturnsInvalidArgs) { |
| 807 | DBus::Path network = "/test/path"; |
| 808 | EXPECT_CALL(*supplicant_interface_proxy_, RemoveNetwork(network)) |
| 809 | .WillRepeatedly(Throw( |
| 810 | DBus::Error( |
| 811 | "fi.w1.wpa_supplicant1.InvalidArgs", |
| 812 | "test threw fi.w1.wpa_supplicant1.InvalidArgs"))); |
| 813 | StartWiFi(); |
| 814 | EXPECT_FALSE(RemoveNetwork(network)); |
| 815 | } |
| 816 | |
| 817 | TEST_F(WiFiMainTest, RemoveNetworkWhenSupplicantReturnsUnknownError) { |
| 818 | DBus::Path network = "/test/path"; |
| 819 | EXPECT_CALL(*supplicant_interface_proxy_, RemoveNetwork(network)) |
| 820 | .WillRepeatedly(Throw( |
| 821 | DBus::Error( |
| 822 | "fi.w1.wpa_supplicant1.UnknownError", |
| 823 | "test threw fi.w1.wpa_supplicant1.UnknownError"))); |
| 824 | StartWiFi(); |
| 825 | EXPECT_FALSE(RemoveNetwork(network)); |
| 826 | } |
| 827 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 828 | TEST_F(WiFiMainTest, Restart) { |
| 829 | EXPECT_CALL(*supplicant_process_proxy_, CreateInterface(_)) |
| 830 | .Times(AnyNumber()) |
| 831 | .WillRepeatedly(Throw( |
| 832 | DBus::Error( |
| 833 | "fi.w1.wpa_supplicant1.InterfaceExists", |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 834 | "test threw fi.w1.wpa_supplicant1.InterfaceExists"))); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 835 | EXPECT_CALL(*supplicant_process_proxy_, GetInterface(_)); |
| 836 | EXPECT_CALL(*supplicant_interface_proxy_, Scan(_)); |
| 837 | StartWiFi(); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 838 | dispatcher_.DispatchPendingEvents(); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | TEST_F(WiFiMainTest, StartClearsState) { |
| 842 | EXPECT_CALL(*supplicant_interface_proxy_, RemoveAllNetworks()); |
| 843 | EXPECT_CALL(*supplicant_interface_proxy_, FlushBSS(_)); |
| 844 | StartWiFi(); |
| 845 | } |
| 846 | |
mukesh agrawal | 2f9df4e | 2012-08-08 12:29:20 -0700 | [diff] [blame] | 847 | TEST_F(WiFiMainTest, ResumeStartsScanWhenIdle) { |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 848 | EXPECT_CALL(*supplicant_interface_proxy_, Scan(_)); |
| 849 | StartWiFi(); |
| 850 | dispatcher_.DispatchPendingEvents(); |
| 851 | Mock::VerifyAndClearExpectations(&supplicant_interface_proxy_); |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 852 | ReportScanDone(); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 853 | ASSERT_TRUE(wifi()->IsIdle()); |
| 854 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Scan(_)); |
mukesh agrawal | 2f9df4e | 2012-08-08 12:29:20 -0700 | [diff] [blame] | 855 | OnAfterResume(); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 856 | dispatcher_.DispatchPendingEvents(); |
| 857 | } |
| 858 | |
mukesh agrawal | 2f9df4e | 2012-08-08 12:29:20 -0700 | [diff] [blame] | 859 | TEST_F(WiFiMainTest, SuspendDoesNotStartScan) { |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 860 | EXPECT_CALL(*supplicant_interface_proxy_, Scan(_)); |
| 861 | StartWiFi(); |
| 862 | dispatcher_.DispatchPendingEvents(); |
| 863 | Mock::VerifyAndClearExpectations(&supplicant_interface_proxy_); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 864 | ASSERT_TRUE(wifi()->IsIdle()); |
| 865 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Scan(_)).Times(0); |
mukesh agrawal | 2f9df4e | 2012-08-08 12:29:20 -0700 | [diff] [blame] | 866 | OnBeforeSuspend(); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 867 | dispatcher_.DispatchPendingEvents(); |
| 868 | } |
| 869 | |
mukesh agrawal | 2f9df4e | 2012-08-08 12:29:20 -0700 | [diff] [blame] | 870 | TEST_F(WiFiMainTest, ResumeDoesNotStartScanWhenNotIdle) { |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 871 | EXPECT_CALL(*supplicant_interface_proxy_, Scan(_)); |
| 872 | StartWiFi(); |
| 873 | |
| 874 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 875 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 876 | Error error; |
mukesh agrawal | 3ab56ac | 2012-05-31 14:41:43 -0700 | [diff] [blame] | 877 | ScopedMockLog log; |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 878 | service->AddEndpoint(ap); |
| 879 | service->AutoConnect(); |
| 880 | EXPECT_FALSE(wifi()->IsIdle()); |
| 881 | dispatcher_.DispatchPendingEvents(); |
| 882 | Mock::VerifyAndClearExpectations(&supplicant_interface_proxy_); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 883 | ASSERT_FALSE(wifi()->IsIdle()); |
mukesh agrawal | 3ab56ac | 2012-05-31 14:41:43 -0700 | [diff] [blame] | 884 | EXPECT_CALL(log, Log(_, _, _)).Times(AnyNumber()); |
| 885 | EXPECT_CALL(log, Log(_, _, EndsWith("already scanning or connected."))); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 886 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Scan(_)).Times(0); |
mukesh agrawal | 2f9df4e | 2012-08-08 12:29:20 -0700 | [diff] [blame] | 887 | OnAfterResume(); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 888 | dispatcher_.DispatchPendingEvents(); |
| 889 | } |
| 890 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 891 | TEST_F(WiFiMainTest, ScanResults) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 892 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 893 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 894 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 895 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 896 | "bss1", "ssid1", "00:00:00:00:00:01", 1, 0, kNetworkModeInfrastructure); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 897 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 898 | "bss2", "ssid2", "00:00:00:00:00:02", 2, 0, kNetworkModeInfrastructure); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 899 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 900 | "bss3", "ssid3", "00:00:00:00:00:03", 3, 0, kNetworkModeInfrastructure); |
| 901 | const uint16 frequency = 2412; |
| 902 | ReportBSS("bss4", "ssid4", "00:00:00:00:00:04", 4, frequency, |
| 903 | kNetworkModeAdHoc); |
| 904 | |
| 905 | const WiFi::EndpointMap &endpoints_by_rpcid = GetEndpointMap(); |
| 906 | EXPECT_EQ(5, endpoints_by_rpcid.size()); |
| 907 | |
| 908 | WiFi::EndpointMap::const_iterator i; |
| 909 | WiFiEndpointRefPtr endpoint; |
| 910 | for (i = endpoints_by_rpcid.begin(); |
| 911 | i != endpoints_by_rpcid.end(); |
| 912 | ++i) { |
| 913 | if (i->second->bssid_string() == "00:00:00:00:00:04") |
| 914 | break; |
| 915 | } |
| 916 | ASSERT_TRUE(i != endpoints_by_rpcid.end()); |
| 917 | EXPECT_EQ(4, i->second->signal_strength()); |
| 918 | EXPECT_EQ(frequency, i->second->frequency()); |
| 919 | EXPECT_EQ("adhoc", i->second->network_mode()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | TEST_F(WiFiMainTest, ScanResultsWithUpdates) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 923 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
| 924 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
| 925 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 926 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 927 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 928 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 929 | "bss1", "ssid1", "00:00:00:00:00:01", 1, 0, kNetworkModeInfrastructure); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 930 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 931 | "bss2", "ssid2", "00:00:00:00:00:02", 2, 0, kNetworkModeInfrastructure); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 932 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 933 | "bss1", "ssid1", "00:00:00:00:00:01", 3, 0, kNetworkModeInfrastructure); |
| 934 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 4, 0, kNetworkModeAdHoc); |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 935 | |
| 936 | const WiFi::EndpointMap &endpoints_by_rpcid = GetEndpointMap(); |
| 937 | EXPECT_EQ(3, endpoints_by_rpcid.size()); |
| 938 | |
| 939 | WiFi::EndpointMap::const_iterator i; |
| 940 | WiFiEndpointRefPtr endpoint; |
| 941 | for (i = endpoints_by_rpcid.begin(); |
| 942 | i != endpoints_by_rpcid.end(); |
| 943 | ++i) { |
| 944 | if (i->second->bssid_string() == "00:00:00:00:00:00") |
| 945 | break; |
| 946 | } |
| 947 | ASSERT_TRUE(i != endpoints_by_rpcid.end()); |
| 948 | EXPECT_EQ(4, i->second->signal_strength()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | TEST_F(WiFiMainTest, ScanCompleted) { |
| 952 | StartWiFi(); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 953 | EXPECT_CALL(*manager(), RegisterService(_)) |
| 954 | .Times(3); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 955 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 956 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 957 | "bss1", "ssid1", "00:00:00:00:00:01", 1, 0, kNetworkModeInfrastructure); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 958 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 959 | "bss2", "ssid2", "00:00:00:00:00:02", 2, 0, kNetworkModeInfrastructure); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 960 | ReportScanDone(); |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 961 | EXPECT_EQ(3, GetServices().size()); |
mukesh agrawal | b385761 | 2012-01-18 16:23:29 -0800 | [diff] [blame] | 962 | |
mukesh agrawal | e9adda1 | 2012-02-09 18:33:48 -0800 | [diff] [blame] | 963 | // BSSes with SSIDs that start with NULL should be filtered. |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 964 | 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] | 965 | EXPECT_EQ(3, GetEndpointMap().size()); |
mukesh agrawal | b385761 | 2012-01-18 16:23:29 -0800 | [diff] [blame] | 966 | EXPECT_EQ(3, GetServices().size()); |
| 967 | |
mukesh agrawal | e9adda1 | 2012-02-09 18:33:48 -0800 | [diff] [blame] | 968 | // BSSes with empty SSIDs should be filtered. |
| 969 | ReportBSS("bss3", string(), "00:00:00:00:00:03", 3, 0, kNetworkModeAdHoc); |
| 970 | EXPECT_EQ(3, GetEndpointMap().size()); |
| 971 | EXPECT_EQ(3, GetServices().size()); |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | TEST_F(WiFiMainTest, EndpointGroupingTogether) { |
| 975 | StartWiFi(); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 976 | |
| 977 | InSequence s; |
| 978 | EXPECT_CALL(*manager(), RegisterService(_)); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 979 | EXPECT_CALL(*manager(), HasService(_)); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 980 | EXPECT_CALL(*manager(), UpdateService(_)); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 981 | ReportBSS("bss0", "ssid", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 982 | ReportBSS("bss1", "ssid", "00:00:00:00:00:01", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 983 | ReportScanDone(); |
| 984 | EXPECT_EQ(1, GetServices().size()); |
| 985 | } |
| 986 | |
| 987 | TEST_F(WiFiMainTest, EndpointGroupingDifferentSSID) { |
| 988 | StartWiFi(); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 989 | EXPECT_CALL(*manager(), RegisterService(_)) |
| 990 | .Times(2); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 991 | ReportBSS("bss0", "ssid1", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 992 | ReportBSS("bss1", "ssid2", "00:00:00:00:00:01", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 993 | ReportScanDone(); |
| 994 | EXPECT_EQ(2, GetServices().size()); |
| 995 | } |
| 996 | |
| 997 | TEST_F(WiFiMainTest, EndpointGroupingDifferentMode) { |
| 998 | StartWiFi(); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 999 | EXPECT_CALL(*manager(), RegisterService(_)) |
| 1000 | .Times(2); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1001 | ReportBSS("bss0", "ssid", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 1002 | ReportBSS("bss1", "ssid", "00:00:00:00:00:01", 0, 0, |
| 1003 | kNetworkModeInfrastructure); |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 1004 | ReportScanDone(); |
| 1005 | EXPECT_EQ(2, GetServices().size()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 1008 | TEST_F(WiFiMainTest, NonExistentBSSRemoved) { |
| 1009 | // Removal of non-existent BSS should not cause a crash. |
| 1010 | StartWiFi(); |
| 1011 | RemoveBSS("bss0"); |
| 1012 | EXPECT_EQ(0, GetServices().size()); |
| 1013 | } |
| 1014 | |
mukesh agrawal | e9adda1 | 2012-02-09 18:33:48 -0800 | [diff] [blame] | 1015 | TEST_F(WiFiMainTest, BSSWithEmptySSIDRemoved) { |
| 1016 | // Removal of BSS with an empty SSID should not cause a crash. |
| 1017 | ReportBSS("bss", string(), "00:00:00:00:00:01", 0, 0, kNetworkModeAdHoc); |
| 1018 | StartWiFi(); |
| 1019 | RemoveBSS("bss"); |
| 1020 | EXPECT_EQ(0, GetServices().size()); |
| 1021 | } |
| 1022 | |
| 1023 | TEST_F(WiFiMainTest, BSSWithNullSSIDRemoved) { |
| 1024 | // Removal of BSS with a NULL SSID should not cause a crash. |
| 1025 | ReportBSS("bss", string(1, 0), "00:00:00:00:00:01", 0, 0, kNetworkModeAdHoc); |
| 1026 | StartWiFi(); |
| 1027 | RemoveBSS("bss"); |
| 1028 | EXPECT_EQ(0, GetServices().size()); |
| 1029 | } |
| 1030 | |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 1031 | TEST_F(WiFiMainTest, LoneBSSRemoved) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1032 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 1033 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1034 | ReportBSS("bss0", "ssid", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 1035 | ReportScanDone(); |
| 1036 | EXPECT_EQ(1, GetServices().size()); |
| 1037 | EXPECT_TRUE(GetServices().front()->IsVisible()); |
| 1038 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1039 | EXPECT_CALL(*manager(), DeregisterService(_)); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 1040 | RemoveBSS("bss0"); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1041 | EXPECT_TRUE(GetServices().empty()); |
| 1042 | } |
| 1043 | |
| 1044 | TEST_F(WiFiMainTest, LoneBSSRemovedWhileConnected) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1045 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1046 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1047 | ReportBSS("bss0", "ssid", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1048 | ReportScanDone(); |
| 1049 | ReportCurrentBSSChanged("bss0"); |
| 1050 | |
| 1051 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Disconnect()); |
| 1052 | EXPECT_CALL(*manager(), DeregisterService(_)); |
| 1053 | RemoveBSS("bss0"); |
| 1054 | EXPECT_TRUE(GetServices().empty()); |
| 1055 | } |
| 1056 | |
| 1057 | TEST_F(WiFiMainTest, LoneBSSRemovedWhileConnectedToHidden) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1058 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
| 1059 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1060 | StartWiFi(); |
| 1061 | |
| 1062 | Error e; |
| 1063 | WiFiServiceRefPtr service = |
| 1064 | GetServiceInner(flimflam::kTypeWifi, "ssid", flimflam::kModeManaged, |
| 1065 | NULL, NULL, true, &e); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 1066 | EXPECT_EQ(1, GetServices().size()); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1067 | |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1068 | ReportBSS("bss", "ssid", "00:00:00:00:00:01", 0, 0, |
| 1069 | kNetworkModeInfrastructure); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1070 | ReportScanDone(); |
| 1071 | ReportCurrentBSSChanged("bss"); |
| 1072 | EXPECT_EQ(1, GetServices().size()); |
| 1073 | |
| 1074 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Disconnect()); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1075 | RemoveBSS("bss"); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1076 | EXPECT_EQ(1, GetServices().size()); |
| 1077 | // Verify expectations now, because WiFi may call UpdateService when |
| 1078 | // WiFi is Stop()-ed (during TearDown()). |
| 1079 | Mock::VerifyAndClearExpectations(manager()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1080 | EXPECT_CALL(*manager(), DeregisterService(_)).Times(AnyNumber()); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | TEST_F(WiFiMainTest, NonSolitaryBSSRemoved) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1084 | EXPECT_CALL(*manager(), RegisterService(_)); |
| 1085 | EXPECT_CALL(*manager(), HasService(_)); |
| 1086 | EXPECT_CALL(*manager(), UpdateService(_)); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 1087 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1088 | ReportBSS("bss0", "ssid", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 1089 | ReportBSS("bss1", "ssid", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 1090 | ReportScanDone(); |
| 1091 | EXPECT_EQ(1, GetServices().size()); |
| 1092 | EXPECT_TRUE(GetServices().front()->IsVisible()); |
| 1093 | |
| 1094 | EXPECT_CALL(*manager(), UpdateService(_)); |
| 1095 | RemoveBSS("bss0"); |
| 1096 | EXPECT_TRUE(GetServices().front()->IsVisible()); |
| 1097 | EXPECT_EQ(1, GetServices().size()); |
| 1098 | } |
| 1099 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 1100 | TEST_F(WiFiMainTest, Connect) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1101 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 1102 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1103 | *supplicant_interface_proxy_; |
| 1104 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 1105 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1106 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 1107 | ReportScanDone(); |
| 1108 | |
| 1109 | { |
| 1110 | InSequence s; |
| 1111 | DBus::Path fake_path("/fake/path"); |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 1112 | WiFiService *service(GetServices().begin()->get()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 1113 | |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 1114 | EXPECT_CALL(supplicant_interface_proxy, AddNetwork(_)) |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 1115 | .WillOnce(Return(fake_path)); |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 1116 | EXPECT_CALL(supplicant_interface_proxy, SelectNetwork(fake_path)); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1117 | InitiateConnect(service); |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 1118 | EXPECT_EQ(static_cast<Service *>(service), |
| 1119 | wifi()->selected_service_.get()); |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 1120 | EXPECT_EQ(Service::kStateAssociating, service->state()); |
| 1121 | EXPECT_FALSE(GetPendingTimeout().IsCancelled()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 1122 | } |
| 1123 | } |
| 1124 | |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1125 | TEST_F(WiFiMainTest, DisconnectPendingService) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1126 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1127 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1128 | *supplicant_interface_proxy_; |
| 1129 | |
| 1130 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1131 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1132 | WiFiService *service(GetServices().begin()->get()); |
| 1133 | InitiateConnect(service); |
| 1134 | |
| 1135 | EXPECT_FALSE(GetPendingService() == NULL); |
Paul Stewart | ff96a84 | 2012-08-13 15:59:10 -0700 | [diff] [blame] | 1136 | EXPECT_TRUE(service->IsConnecting()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1137 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()); |
| 1138 | InitiateDisconnect(service); |
Paul Stewart | ff96a84 | 2012-08-13 15:59:10 -0700 | [diff] [blame] | 1139 | EXPECT_FALSE(service->IsConnecting()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1140 | |
| 1141 | EXPECT_TRUE(GetPendingService() == NULL); |
| 1142 | } |
| 1143 | |
| 1144 | TEST_F(WiFiMainTest, DisconnectPendingServiceWithCurrent) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1145 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 1146 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _, _, _)).Times(AnyNumber()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1147 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(AnyNumber()); |
| 1148 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1149 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1150 | *supplicant_interface_proxy_; |
| 1151 | |
| 1152 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1153 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 1154 | ReportBSS("bss1", "ssid1", "00:00:00:00:00:01", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1155 | WiFiService *service0(GetServices()[0].get()); |
| 1156 | WiFiService *service1(GetServices()[1].get()); |
| 1157 | |
| 1158 | InitiateConnect(service0); |
| 1159 | ReportCurrentBSSChanged("bss0"); |
| 1160 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 1161 | InitiateConnect(service1); |
| 1162 | |
| 1163 | EXPECT_EQ(service0, GetCurrentService()); |
| 1164 | EXPECT_EQ(service1, GetPendingService()); |
| 1165 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()); |
| 1166 | InitiateDisconnect(service1); |
| 1167 | |
| 1168 | // |current_service_| will be unchanged until supplicant signals |
| 1169 | // that CurrentBSS has changed. |
| 1170 | EXPECT_EQ(service0, GetCurrentService()); |
| 1171 | // |pending_service_| is updated immediately. |
| 1172 | EXPECT_TRUE(GetPendingService() == NULL); |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 1173 | EXPECT_TRUE(GetPendingTimeout().IsCancelled()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | TEST_F(WiFiMainTest, DisconnectCurrentService) { |
| 1177 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1178 | *supplicant_interface_proxy_; |
Paul Stewart | 549d44c | 2012-07-03 12:40:25 -0700 | [diff] [blame] | 1179 | WiFiService *service(SetupConnectedService(DBus::Path())); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1180 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()); |
| 1181 | InitiateDisconnect(service); |
| 1182 | |
| 1183 | // |current_service_| should not change until supplicant reports |
| 1184 | // a BSS change. |
| 1185 | EXPECT_EQ(service, GetCurrentService()); |
| 1186 | } |
| 1187 | |
Christopher Wiley | c618448 | 2012-10-24 15:31:56 -0700 | [diff] [blame] | 1188 | TEST_F(WiFiMainTest, DisconnectCurrentServiceWithErrors) { |
| 1189 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1190 | *supplicant_interface_proxy_; |
| 1191 | WiFiService *service(SetupConnectedService(DBus::Path())); |
| 1192 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()) |
| 1193 | .WillOnce(InvokeWithoutArgs(this, (&WiFiMainTest::ThrowDBusError))); |
| 1194 | InitiateDisconnect(service); |
| 1195 | |
| 1196 | // We may sometimes fail to disconnect via supplicant, and we patch up some |
| 1197 | // state when this happens. |
| 1198 | EXPECT_EQ(NULL, GetCurrentService().get()); |
| 1199 | EXPECT_EQ(NULL, wifi()->selected_service().get()); |
| 1200 | } |
| 1201 | |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1202 | TEST_F(WiFiMainTest, DisconnectCurrentServiceWithPending) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1203 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 1204 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _, _, _)).Times(AnyNumber()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1205 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(AnyNumber()); |
| 1206 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1207 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1208 | *supplicant_interface_proxy_; |
| 1209 | |
| 1210 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1211 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 1212 | ReportBSS("bss1", "ssid1", "00:00:00:00:00:01", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1213 | WiFiService *service0(GetServices()[0].get()); |
| 1214 | WiFiService *service1(GetServices()[1].get()); |
| 1215 | |
| 1216 | InitiateConnect(service0); |
| 1217 | ReportCurrentBSSChanged("bss0"); |
| 1218 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 1219 | InitiateConnect(service1); |
| 1220 | |
| 1221 | EXPECT_EQ(service0, GetCurrentService()); |
| 1222 | EXPECT_EQ(service1, GetPendingService()); |
| 1223 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()) |
| 1224 | .Times(0); |
| 1225 | InitiateDisconnect(service0); |
| 1226 | |
| 1227 | EXPECT_EQ(service0, GetCurrentService()); |
| 1228 | EXPECT_EQ(service1, GetPendingService()); |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 1229 | EXPECT_FALSE(GetPendingTimeout().IsCancelled()); |
| 1230 | } |
| 1231 | |
| 1232 | TEST_F(WiFiMainTest, TimeoutPendingService) { |
| 1233 | StartWiFi(); |
| 1234 | dispatcher_.DispatchPendingEvents(); |
| 1235 | const base::CancelableClosure &pending_timeout = GetPendingTimeout(); |
| 1236 | EXPECT_TRUE(pending_timeout.IsCancelled()); |
| 1237 | |
| 1238 | InSequence seq; |
| 1239 | MockWiFiServiceRefPtr service = MakeMockService(flimflam::kSecurityNone); |
| 1240 | EXPECT_CALL(*service, SetState(Service::kStateAssociating)); |
| 1241 | InitiateConnect(service); |
| 1242 | EXPECT_FALSE(pending_timeout.IsCancelled()); |
| 1243 | EXPECT_EQ(service, GetPendingService()); |
| 1244 | |
Paul Stewart | ff96a84 | 2012-08-13 15:59:10 -0700 | [diff] [blame] | 1245 | { |
| 1246 | InSequence seq; |
| 1247 | EXPECT_CALL(*service, SetState(Service::kStateIdle)); |
| 1248 | EXPECT_CALL(*service, SetFailure(Service::kFailureOutOfRange)); |
| 1249 | pending_timeout.callback().Run(); |
| 1250 | } |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 1251 | EXPECT_EQ(NULL, GetPendingService().get()); |
| 1252 | |
| 1253 | // Verify expectations now, because WiFi may report other state changes |
| 1254 | // when WiFi is Stop()-ed (during TearDown()). |
| 1255 | Mock::VerifyAndClearExpectations(service.get()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | TEST_F(WiFiMainTest, DisconnectInvalidService) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1259 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1260 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1261 | *supplicant_interface_proxy_; |
| 1262 | |
| 1263 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1264 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1265 | WiFiService *service(GetServices().begin()->get()); |
| 1266 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()) |
| 1267 | .Times(0); |
| 1268 | InitiateDisconnect(service); |
| 1269 | } |
| 1270 | |
| 1271 | TEST_F(WiFiMainTest, DisconnectCurrentServiceFailure) { |
| 1272 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1273 | *supplicant_interface_proxy_; |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1274 | DBus::Path fake_path("/fake/path"); |
Paul Stewart | 549d44c | 2012-07-03 12:40:25 -0700 | [diff] [blame] | 1275 | WiFiService *service(SetupConnectedService(fake_path)); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1276 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()) |
| 1277 | .WillRepeatedly(Throw( |
| 1278 | DBus::Error( |
| 1279 | "fi.w1.wpa_supplicant1.NotConnected", |
| 1280 | "test threw fi.w1.wpa_supplicant1.NotConnected"))); |
| 1281 | EXPECT_CALL(supplicant_interface_proxy, RemoveNetwork(fake_path)); |
| 1282 | InitiateDisconnect(service); |
| 1283 | |
| 1284 | EXPECT_TRUE(GetCurrentService() == NULL); |
| 1285 | } |
| 1286 | |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 1287 | TEST_F(WiFiMainTest, Stop) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1288 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 1289 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1290 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 1291 | ReportScanDone(); |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 1292 | |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 1293 | EXPECT_CALL(*manager(), DeregisterService(_)); |
| 1294 | StopWiFi(); |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 1295 | EXPECT_TRUE(GetScanTimer().IsCancelled()); |
mukesh agrawal | c4f368f | 2012-06-04 19:45:52 -0700 | [diff] [blame] | 1296 | EXPECT_FALSE(wifi()->weak_ptr_factory_.HasWeakPtrs()); |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 1297 | } |
| 1298 | |
Paul Stewart | 549d44c | 2012-07-03 12:40:25 -0700 | [diff] [blame] | 1299 | TEST_F(WiFiMainTest, StopWhileConnected) { |
| 1300 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1301 | *supplicant_interface_proxy_; |
| 1302 | WiFiService *service(SetupConnectedService(DBus::Path())); |
| 1303 | EXPECT_CALL(*manager(), DeregisterService(ServiceRefPtr(service))) |
| 1304 | .WillOnce(Invoke(this, &WiFiObjectTest::UnloadService)); |
| 1305 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()); |
| 1306 | StopWiFi(); |
| 1307 | EXPECT_TRUE(GetCurrentService() == NULL); |
| 1308 | } |
| 1309 | |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1310 | TEST_F(WiFiMainTest, ReconnectTimer) { |
| 1311 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1312 | *supplicant_interface_proxy_; |
| 1313 | WiFiService *service(SetupConnectedService(DBus::Path())); |
| 1314 | service->SetState(Service::kStateConnected); |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 1315 | EXPECT_TRUE(GetReconnectTimeoutCallback().IsCancelled()); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1316 | ReportStateChanged(wpa_supplicant::kInterfaceStateDisconnected); |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 1317 | EXPECT_FALSE(GetReconnectTimeoutCallback().IsCancelled()); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1318 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 1319 | EXPECT_TRUE(GetReconnectTimeoutCallback().IsCancelled()); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1320 | ReportStateChanged(wpa_supplicant::kInterfaceStateDisconnected); |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 1321 | EXPECT_FALSE(GetReconnectTimeoutCallback().IsCancelled()); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1322 | ReportCurrentBSSChanged(kBSSName); |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 1323 | EXPECT_TRUE(GetReconnectTimeoutCallback().IsCancelled()); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1324 | ReportStateChanged(wpa_supplicant::kInterfaceStateDisconnected); |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 1325 | EXPECT_FALSE(GetReconnectTimeoutCallback().IsCancelled()); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1326 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()); |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 1327 | GetReconnectTimeoutCallback().callback().Run(); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1328 | Mock::VerifyAndClearExpectations(&supplicant_interface_proxy_); |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 1329 | EXPECT_TRUE(GetReconnectTimeoutCallback().IsCancelled()); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1332 | TEST_F(WiFiMainTest, GetWifiServiceOpen) { |
| 1333 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1334 | GetOpenService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1335 | EXPECT_TRUE(e.IsSuccess()); |
| 1336 | } |
| 1337 | |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1338 | TEST_F(WiFiMainTest, GetWifiServiceOpenNoSSID) { |
| 1339 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1340 | GetOpenService(flimflam::kTypeWifi, NULL, flimflam::kModeManaged, &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1341 | EXPECT_EQ(Error::kInvalidArguments, e.type()); |
| 1342 | EXPECT_EQ("must specify SSID", e.message()); |
| 1343 | } |
| 1344 | |
| 1345 | TEST_F(WiFiMainTest, GetWifiServiceOpenLongSSID) { |
| 1346 | Error e; |
| 1347 | GetOpenService( |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1348 | flimflam::kTypeWifi, "123456789012345678901234567890123", |
| 1349 | flimflam::kModeManaged, &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1350 | EXPECT_EQ(Error::kInvalidNetworkName, e.type()); |
| 1351 | EXPECT_EQ("SSID is too long", e.message()); |
| 1352 | } |
| 1353 | |
| 1354 | TEST_F(WiFiMainTest, GetWifiServiceOpenShortSSID) { |
| 1355 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1356 | GetOpenService(flimflam::kTypeWifi, "", flimflam::kModeManaged, &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1357 | EXPECT_EQ(Error::kInvalidNetworkName, e.type()); |
| 1358 | EXPECT_EQ("SSID is too short", e.message()); |
| 1359 | } |
| 1360 | |
| 1361 | TEST_F(WiFiMainTest, GetWifiServiceOpenBadMode) { |
| 1362 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1363 | GetOpenService(flimflam::kTypeWifi, "an_ssid", "ad-hoc", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1364 | EXPECT_EQ(Error::kNotSupported, e.type()); |
| 1365 | EXPECT_EQ("service mode is unsupported", e.message()); |
| 1366 | } |
| 1367 | |
| 1368 | TEST_F(WiFiMainTest, GetWifiServiceOpenNoMode) { |
| 1369 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1370 | GetOpenService(flimflam::kTypeWifi, "an_ssid", NULL, &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1371 | EXPECT_TRUE(e.IsSuccess()); |
| 1372 | } |
| 1373 | |
| 1374 | TEST_F(WiFiMainTest, GetWifiServiceRSN) { |
| 1375 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1376 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1377 | flimflam::kSecurityRsn, "secure password", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1378 | EXPECT_TRUE(e.IsSuccess()); |
| 1379 | } |
| 1380 | |
| 1381 | TEST_F(WiFiMainTest, GetWifiServiceRSNNoPassword) { |
mukesh agrawal | b172e4a | 2012-04-25 18:15:30 -0700 | [diff] [blame] | 1382 | // When configuring hidden networks, Chrome expects to be able to |
| 1383 | // GetService w/o a password, and supply the password with |
| 1384 | // SetProperty afterwards. |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1385 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1386 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1387 | flimflam::kSecurityRsn, NULL, &e); |
mukesh agrawal | b172e4a | 2012-04-25 18:15:30 -0700 | [diff] [blame] | 1388 | EXPECT_TRUE(e.IsSuccess()); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | TEST_F(WiFiMainTest, GetWifiServiceBadSecurity) { |
| 1392 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1393 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, "rot-13", |
| 1394 | NULL, &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1395 | EXPECT_EQ(Error::kNotSupported, e.type()); |
| 1396 | EXPECT_EQ("security mode is unsupported", e.message()); |
| 1397 | } |
| 1398 | |
| 1399 | TEST_F(WiFiMainTest, GetWifiServiceWEPNoPassword) { |
mukesh agrawal | b172e4a | 2012-04-25 18:15:30 -0700 | [diff] [blame] | 1400 | // When configuring hidden networks, Chrome expects to be able to |
| 1401 | // GetService w/o a password, and supply the password with |
| 1402 | // SetProperty afterwards. |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1403 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1404 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1405 | flimflam::kSecurityWep, NULL, &e); |
mukesh agrawal | b172e4a | 2012-04-25 18:15:30 -0700 | [diff] [blame] | 1406 | EXPECT_TRUE(e.IsSuccess()); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | TEST_F(WiFiMainTest, GetWifiServiceWEPEmptyPassword) { |
| 1410 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1411 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1412 | flimflam::kSecurityWep, "", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1413 | EXPECT_EQ(Error::kInvalidPassphrase, e.type()); |
| 1414 | } |
| 1415 | |
| 1416 | TEST_F(WiFiMainTest, GetWifiServiceWEP40ASCII) { |
| 1417 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1418 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1419 | flimflam::kSecurityWep, "abcde", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1420 | EXPECT_TRUE(e.IsSuccess()); |
| 1421 | } |
| 1422 | |
| 1423 | TEST_F(WiFiMainTest, GetWifiServiceWEP104ASCII) { |
| 1424 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1425 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1426 | flimflam::kSecurityWep, "abcdefghijklm", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1427 | EXPECT_TRUE(e.IsSuccess()); |
| 1428 | } |
| 1429 | |
| 1430 | TEST_F(WiFiMainTest, GetWifiServiceWEP40ASCIIWithKeyIndex) { |
| 1431 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1432 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1433 | flimflam::kSecurityWep, "0:abcdefghijklm", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1434 | EXPECT_TRUE(e.IsSuccess()); |
| 1435 | } |
| 1436 | |
| 1437 | TEST_F(WiFiMainTest, GetWifiServiceWEP40Hex) { |
| 1438 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1439 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1440 | flimflam::kSecurityWep, "0102030405", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1441 | EXPECT_TRUE(e.IsSuccess()); |
| 1442 | } |
| 1443 | |
| 1444 | TEST_F(WiFiMainTest, GetWifiServiceWEP40HexBadPassphrase) { |
| 1445 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1446 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1447 | flimflam::kSecurityWep, "O102030405", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1448 | EXPECT_EQ(Error::kInvalidPassphrase, e.type()); |
| 1449 | } |
| 1450 | |
| 1451 | TEST_F(WiFiMainTest, GetWifiServiceWEP40HexWithKeyIndexBadPassphrase) { |
| 1452 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1453 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1454 | flimflam::kSecurityWep, "1:O102030405", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1455 | EXPECT_EQ(Error::kInvalidPassphrase, e.type()); |
| 1456 | } |
| 1457 | |
| 1458 | TEST_F(WiFiMainTest, GetWifiServiceWEP40HexWithKeyIndexAndBaseBadPassphrase) { |
| 1459 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1460 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1461 | flimflam::kSecurityWep, "1:0xO102030405", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1462 | EXPECT_EQ(Error::kInvalidPassphrase, e.type()); |
| 1463 | } |
| 1464 | |
| 1465 | TEST_F(WiFiMainTest, GetWifiServiceWEP40HexWithBaseBadPassphrase) { |
| 1466 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1467 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1468 | flimflam::kSecurityWep, "0xO102030405", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1469 | EXPECT_EQ(Error::kInvalidPassphrase, e.type()); |
| 1470 | } |
| 1471 | |
| 1472 | TEST_F(WiFiMainTest, GetWifiServiceWEP104Hex) { |
| 1473 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1474 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1475 | flimflam::kSecurityWep, "0102030405060708090a0b0c0d", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1476 | EXPECT_TRUE(e.IsSuccess()); |
| 1477 | } |
| 1478 | |
| 1479 | TEST_F(WiFiMainTest, GetWifiServiceWEP104HexUppercase) { |
| 1480 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1481 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1482 | flimflam::kSecurityWep, "0102030405060708090A0B0C0D", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1483 | EXPECT_TRUE(e.IsSuccess()); |
| 1484 | } |
| 1485 | |
| 1486 | TEST_F(WiFiMainTest, GetWifiServiceWEP104HexWithKeyIndex) { |
| 1487 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1488 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1489 | flimflam::kSecurityWep, "0:0102030405060708090a0b0c0d", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1490 | EXPECT_TRUE(e.IsSuccess()); |
| 1491 | } |
| 1492 | |
| 1493 | TEST_F(WiFiMainTest, GetWifiServiceWEP104HexWithKeyIndexAndBase) { |
| 1494 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1495 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1496 | flimflam::kSecurityWep, "0:0x0102030405060708090a0b0c0d", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1497 | EXPECT_TRUE(e.IsSuccess()); |
| 1498 | } |
| 1499 | |
mukesh agrawal | 8ede052 | 2011-10-03 14:57:44 -0700 | [diff] [blame] | 1500 | class WiFiGetServiceSuccessTest : public WiFiMainTest {}; |
| 1501 | class WiFiGetServiceFailureTest : public WiFiMainTest {}; |
| 1502 | |
| 1503 | TEST_P(WiFiGetServiceSuccessTest, Passphrase) { |
| 1504 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1505 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1506 | flimflam::kSecurityWpa, GetParam().c_str(), &e); |
mukesh agrawal | 8ede052 | 2011-10-03 14:57:44 -0700 | [diff] [blame] | 1507 | EXPECT_TRUE(e.IsSuccess()); |
| 1508 | } |
| 1509 | |
| 1510 | TEST_P(WiFiGetServiceFailureTest, Passphrase) { |
| 1511 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1512 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1513 | flimflam::kSecurityWpa, GetParam().c_str(), &e); |
mukesh agrawal | 8ede052 | 2011-10-03 14:57:44 -0700 | [diff] [blame] | 1514 | EXPECT_EQ(Error::kInvalidPassphrase, e.type()); |
| 1515 | } |
| 1516 | |
| 1517 | INSTANTIATE_TEST_CASE_P( |
| 1518 | WiFiGetServiceSuccessTestInstance, |
| 1519 | WiFiGetServiceSuccessTest, |
| 1520 | Values( |
| 1521 | string(IEEE_80211::kWPAAsciiMinLen, 'Z'), |
| 1522 | string(IEEE_80211::kWPAAsciiMaxLen, 'Z'), |
| 1523 | // subtle: invalid length for hex key, but valid as ascii passphrase |
| 1524 | string(IEEE_80211::kWPAHexLen-1, '1'), |
| 1525 | string(IEEE_80211::kWPAHexLen, '1'))); |
| 1526 | |
| 1527 | INSTANTIATE_TEST_CASE_P( |
| 1528 | WiFiGetServiceFailureTestInstance, |
| 1529 | WiFiGetServiceFailureTest, |
| 1530 | Values( |
| 1531 | string(IEEE_80211::kWPAAsciiMinLen-1, 'Z'), |
| 1532 | string(IEEE_80211::kWPAAsciiMaxLen+1, 'Z'), |
| 1533 | string(IEEE_80211::kWPAHexLen+1, '1'))); |
| 1534 | |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1535 | TEST_F(WiFiMainTest, FindServiceWEP) { |
| 1536 | const string ssid("an_ssid"); |
| 1537 | { |
| 1538 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1539 | GetService(flimflam::kTypeWifi, ssid.c_str(), flimflam::kModeManaged, |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1540 | flimflam::kSecurityWep, "abcde", &e); |
| 1541 | EXPECT_TRUE(e.IsSuccess()); |
| 1542 | } |
| 1543 | vector<uint8_t> ssid_bytes(ssid.begin(), ssid.end()); |
| 1544 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1545 | EXPECT_TRUE(FindService(ssid_bytes, flimflam::kModeManaged, |
| 1546 | flimflam::kSecurityWep).get()); |
| 1547 | EXPECT_FALSE(FindService(ssid_bytes, flimflam::kModeManaged, |
| 1548 | flimflam::kSecurityWpa).get()); |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | TEST_F(WiFiMainTest, FindServiceWPA) { |
| 1552 | const string ssid("an_ssid"); |
| 1553 | { |
| 1554 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1555 | GetService(flimflam::kTypeWifi, ssid.c_str(), flimflam::kModeManaged, |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1556 | flimflam::kSecurityRsn, "abcdefgh", &e); |
| 1557 | EXPECT_TRUE(e.IsSuccess()); |
| 1558 | } |
| 1559 | vector<uint8_t> ssid_bytes(ssid.begin(), ssid.end()); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1560 | WiFiServiceRefPtr wpa_service(FindService(ssid_bytes, flimflam::kModeManaged, |
| 1561 | flimflam::kSecurityWpa)); |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1562 | EXPECT_TRUE(wpa_service.get()); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1563 | WiFiServiceRefPtr rsn_service(FindService(ssid_bytes, flimflam::kModeManaged, |
| 1564 | flimflam::kSecurityRsn)); |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1565 | EXPECT_TRUE(rsn_service.get()); |
| 1566 | EXPECT_EQ(wpa_service.get(), rsn_service.get()); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1567 | WiFiServiceRefPtr psk_service(FindService(ssid_bytes, flimflam::kModeManaged, |
| 1568 | flimflam::kSecurityPsk)); |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1569 | EXPECT_EQ(wpa_service.get(), psk_service.get()); |
| 1570 | // Indirectly test FindService by doing a GetService on something that |
| 1571 | // already exists. |
| 1572 | { |
| 1573 | Error e; |
| 1574 | WiFiServiceRefPtr wpa_service2( |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1575 | GetServiceInner(flimflam::kTypeWifi, ssid.c_str(), |
| 1576 | flimflam::kModeManaged, flimflam::kSecurityWpa, |
| 1577 | "abcdefgh", false, &e)); |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1578 | EXPECT_TRUE(e.IsSuccess()); |
| 1579 | EXPECT_EQ(wpa_service.get(), wpa_service2.get()); |
| 1580 | } |
| 1581 | } |
| 1582 | |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1583 | TEST_F(WiFiMainTest, GetServiceWithGUID) { |
| 1584 | // Perform a GetService that also configures properties in the base Service |
| 1585 | // class using Service::Configure(). |
| 1586 | KeyValueStore args; |
| 1587 | args.SetString(flimflam::kTypeProperty, flimflam::kTypeWifi); |
| 1588 | args.SetString(flimflam::kSSIDProperty, "ssid"); |
| 1589 | args.SetString(flimflam::kSecurityProperty, flimflam::kSecurityNone); |
| 1590 | const string kGUID = "aguid"; // Stored as a registered Service property. |
| 1591 | args.SetString(flimflam::kGuidProperty, kGUID); |
| 1592 | Error e; |
| 1593 | WiFiServiceRefPtr service = GetServiceWithKeyValues(args, &e); |
| 1594 | EXPECT_TRUE(e.IsSuccess()); |
| 1595 | EXPECT_EQ(kGUID, service->guid()); |
| 1596 | } |
| 1597 | |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 1598 | MATCHER_P(HasHiddenSSID, ssid, "") { |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1599 | map<string, DBus::Variant>::const_iterator it = |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 1600 | arg.find(wpa_supplicant::kPropertyScanSSIDs); |
| 1601 | if (it == arg.end()) { |
| 1602 | return false; |
| 1603 | } |
| 1604 | |
| 1605 | const DBus::Variant &ssids_variant = it->second; |
| 1606 | EXPECT_TRUE(DBusAdaptor::IsByteArrays(ssids_variant.signature())); |
| 1607 | const ByteArrays &ssids = it->second.operator ByteArrays(); |
| 1608 | // A valid Scan containing a single hidden SSID should contain |
| 1609 | // two SSID entries: one containing the SSID we are looking for, |
| 1610 | // and an empty entry, signifying that we also want to do a |
| 1611 | // broadcast probe request for all non-hidden APs as well. |
| 1612 | return ssids.size() == 2 && |
| 1613 | string(ssids[0].begin(), ssids[0].end()) == ssid && |
| 1614 | ssids[1].empty(); |
| 1615 | } |
| 1616 | |
| 1617 | TEST_F(WiFiMainTest, ScanHidden) { |
| 1618 | EXPECT_CALL(*supplicant_process_proxy_, CreateInterface(_)); |
| 1619 | EXPECT_CALL(*supplicant_process_proxy_, GetInterface(_)) |
| 1620 | .Times(AnyNumber()) |
| 1621 | .WillRepeatedly(Throw( |
| 1622 | DBus::Error( |
| 1623 | "fi.w1.wpa_supplicant1.InterfaceUnknown", |
| 1624 | "test threw fi.w1.wpa_supplicant1.InterfaceUnknown"))); |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1625 | scoped_refptr<MockProfile> profile( |
| 1626 | new NiceMock<MockProfile>(control_interface(), manager(), "")); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1627 | { |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1628 | // Create a hidden service with an associated profile. |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1629 | Error e; |
| 1630 | WiFiServiceRefPtr service = |
| 1631 | GetServiceInner(flimflam::kTypeWifi, "ssid0", flimflam::kModeManaged, |
| 1632 | NULL, NULL, true, &e); |
| 1633 | EXPECT_TRUE(e.IsSuccess()); |
| 1634 | EXPECT_TRUE(service->hidden_ssid()); |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1635 | service->set_profile(profile); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1636 | } |
| 1637 | { |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1638 | // Create a hidden service without an associated profile. |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1639 | Error e; |
| 1640 | WiFiServiceRefPtr service = |
| 1641 | GetServiceInner(flimflam::kTypeWifi, "ssid1", flimflam::kModeManaged, |
| 1642 | NULL, NULL, true, &e); |
| 1643 | EXPECT_TRUE(e.IsSuccess()); |
| 1644 | EXPECT_TRUE(service->hidden_ssid()); |
| 1645 | } |
| 1646 | { |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1647 | // Create a non-hidden service with an associated profile. |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1648 | Error e; |
| 1649 | WiFiServiceRefPtr service = |
| 1650 | GetServiceInner(flimflam::kTypeWifi, "ssid2", flimflam::kModeManaged, |
| 1651 | NULL, NULL, false, &e); |
| 1652 | EXPECT_TRUE(e.IsSuccess()); |
| 1653 | EXPECT_FALSE(service->hidden_ssid()); |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1654 | service->set_profile(profile); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1655 | } |
| 1656 | EXPECT_CALL(*supplicant_interface_proxy_, Scan(HasHiddenSSID("ssid0"))); |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 1657 | StartWiFi(); |
| 1658 | dispatcher_.DispatchPendingEvents(); |
| 1659 | } |
| 1660 | |
Paul Stewart | fae4dae | 2012-09-13 07:43:32 -0700 | [diff] [blame] | 1661 | TEST_F(WiFiMainTest, ScanWiFiDisabledAfterResume) { |
| 1662 | ScopedMockLog log; |
| 1663 | EXPECT_CALL(log, Log(_, _, _)).Times(AnyNumber()); |
| 1664 | EXPECT_CALL(log, Log(_, _, EndsWith( |
| 1665 | "Ignoring scan request while device is not enabled."))).Times(1); |
| 1666 | EXPECT_CALL(*supplicant_interface_proxy_, Scan(_)).Times(0); |
| 1667 | StartWiFi(); |
| 1668 | StopWiFi(); |
| 1669 | // A scan is queued when WiFi resumes. |
| 1670 | OnAfterResume(); |
| 1671 | dispatcher_.DispatchPendingEvents(); |
| 1672 | } |
| 1673 | |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1674 | TEST_F(WiFiMainTest, InitialSupplicantState) { |
| 1675 | EXPECT_EQ(WiFi::kInterfaceStateUnknown, GetSupplicantState()); |
| 1676 | } |
| 1677 | |
| 1678 | TEST_F(WiFiMainTest, StateChangeNoService) { |
| 1679 | // State change should succeed even if there is no pending Service. |
| 1680 | ReportStateChanged(wpa_supplicant::kInterfaceStateScanning); |
| 1681 | EXPECT_EQ(wpa_supplicant::kInterfaceStateScanning, GetSupplicantState()); |
| 1682 | } |
| 1683 | |
| 1684 | TEST_F(WiFiMainTest, StateChangeWithService) { |
| 1685 | // Forward transition should trigger a Service state change. |
| 1686 | StartWiFi(); |
| 1687 | dispatcher_.DispatchPendingEvents(); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 1688 | MockWiFiServiceRefPtr service = MakeMockService(flimflam::kSecurityNone); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1689 | InitiateConnect(service); |
| 1690 | EXPECT_CALL(*service.get(), SetState(Service::kStateAssociating)); |
| 1691 | ReportStateChanged(wpa_supplicant::kInterfaceStateAssociated); |
| 1692 | // Verify expectations now, because WiFi may report other state changes |
| 1693 | // when WiFi is Stop()-ed (during TearDown()). |
| 1694 | Mock::VerifyAndClearExpectations(service.get()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1695 | EXPECT_CALL(*service.get(), SetState(_)).Times(AnyNumber()); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1696 | } |
| 1697 | |
| 1698 | TEST_F(WiFiMainTest, StateChangeBackwardsWithService) { |
| 1699 | // Some backwards transitions should not trigger a Service state change. |
| 1700 | // Supplicant state should still be updated, however. |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 1701 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _, _, _)).Times(AnyNumber()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1702 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(AnyNumber()); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1703 | StartWiFi(); |
| 1704 | dispatcher_.DispatchPendingEvents(); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 1705 | MockWiFiServiceRefPtr service = MakeMockService(flimflam::kSecurityNone); |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 1706 | EXPECT_CALL(*service.get(), SetState(Service::kStateAssociating)); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1707 | EXPECT_CALL(*service.get(), SetState(Service::kStateConfiguring)); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1708 | InitiateConnect(service); |
| 1709 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1710 | ReportStateChanged(wpa_supplicant::kInterfaceStateAuthenticating); |
| 1711 | EXPECT_EQ(wpa_supplicant::kInterfaceStateAuthenticating, |
| 1712 | GetSupplicantState()); |
| 1713 | // Verify expectations now, because WiFi may report other state changes |
| 1714 | // when WiFi is Stop()-ed (during TearDown()). |
| 1715 | Mock::VerifyAndClearExpectations(service.get()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1716 | EXPECT_CALL(*service.get(), SetState(_)).Times(AnyNumber()); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1717 | } |
| 1718 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1719 | TEST_F(WiFiMainTest, LoadHiddenServicesFailWithNoGroups) { |
| 1720 | StrictMock<MockStore> storage; |
| 1721 | EXPECT_CALL(storage, GetGroupsWithKey(flimflam::kWifiHiddenSsid)) |
| 1722 | .WillOnce(Return(set<string>())); |
| 1723 | EXPECT_FALSE(LoadHiddenServices(&storage)); |
| 1724 | } |
| 1725 | |
| 1726 | TEST_F(WiFiMainTest, LoadHiddenServicesFailWithMissingHidden) { |
| 1727 | string id; |
| 1728 | StrictMock<MockStore> storage; |
| 1729 | SetupHiddenStorage(&storage, "an_ssid", &id); |
| 1730 | // Missing "Hidden" property. |
| 1731 | EXPECT_CALL(storage, GetBool(StrEq(id), flimflam::kWifiHiddenSsid, _)) |
| 1732 | .WillOnce(Return(false)); |
| 1733 | EXPECT_FALSE(LoadHiddenServices(&storage)); |
| 1734 | } |
| 1735 | |
| 1736 | TEST_F(WiFiMainTest, LoadHiddenServicesFailWithFalseHidden) { |
| 1737 | string id; |
| 1738 | StrictMock<MockStore> storage; |
| 1739 | SetupHiddenStorage(&storage, "an_ssid", &id); |
| 1740 | // "Hidden" property set to "false". |
| 1741 | EXPECT_CALL(storage, GetBool(StrEq(id), flimflam::kWifiHiddenSsid, _)) |
| 1742 | .WillOnce(DoAll(SetArgumentPointee<2>(true), Return(false))); |
| 1743 | EXPECT_FALSE(LoadHiddenServices(&storage)); |
| 1744 | } |
| 1745 | |
| 1746 | TEST_F(WiFiMainTest, LoadHiddenServicesFailWithMissingSSID) { |
| 1747 | string id; |
| 1748 | StrictMock<MockStore> storage; |
| 1749 | SetupHiddenStorage(&storage, "an_ssid", &id); |
| 1750 | // Missing "SSID" property. |
| 1751 | EXPECT_CALL(storage, GetString(StrEq(id), flimflam::kSSIDProperty, _)) |
| 1752 | .WillOnce(Return(false)); |
| 1753 | EXPECT_FALSE(LoadHiddenServices(&storage)); |
| 1754 | } |
| 1755 | |
| 1756 | |
| 1757 | TEST_F(WiFiMainTest, LoadHiddenServicesFailWithFoundService) { |
| 1758 | StrictMock<MockStore> storage; |
| 1759 | string id; |
| 1760 | SetupHiddenStorage(&storage, "an_ssid", &id); |
| 1761 | Error e; |
| 1762 | GetOpenService(flimflam::kTypeWifi, "an_ssid", NULL, &e); |
| 1763 | ASSERT_TRUE(e.IsSuccess()); |
| 1764 | EXPECT_FALSE(LoadHiddenServices(&storage)); |
| 1765 | } |
| 1766 | |
| 1767 | TEST_F(WiFiMainTest, LoadHiddenServicesSuccess) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1768 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1769 | StrictMock<MockStore> storage; |
| 1770 | string ssid("an_ssid"); |
| 1771 | string id; |
| 1772 | SetupHiddenStorage(&storage, ssid, &id); |
| 1773 | EXPECT_TRUE(LoadHiddenServices(&storage)); |
| 1774 | vector<uint8_t> ssid_bytes(ssid.begin(), ssid.end()); |
| 1775 | EXPECT_TRUE(FindService(ssid_bytes, flimflam::kModeManaged, |
| 1776 | flimflam::kSecurityNone).get()); |
| 1777 | } |
| 1778 | |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1779 | TEST_F(WiFiMainTest, CurrentBSSChangeConnectedToDisconnected) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1780 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 1781 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _, _, _)).Times(AnyNumber()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1782 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(AnyNumber()); |
| 1783 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1784 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 1785 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 1786 | |
| 1787 | // Note that the BSS handle used in this test ("an_ap") is not |
| 1788 | // intended to reflect the format used by supplicant. It's just |
| 1789 | // convenient for testing. |
| 1790 | |
| 1791 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1792 | ReportBSS("an_ap", ap->ssid_string(), ap->bssid_string(), 0, 0, |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1793 | kNetworkModeInfrastructure); |
| 1794 | InitiateConnect(service); |
| 1795 | EXPECT_EQ(service, GetPendingService().get()); |
| 1796 | |
| 1797 | ReportCurrentBSSChanged("an_ap"); |
| 1798 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 1799 | EXPECT_EQ(Service::kStateConfiguring, service->state()); |
| 1800 | EXPECT_EQ(service, GetCurrentService().get()); |
| 1801 | EXPECT_EQ(NULL, GetPendingService().get()); |
| 1802 | |
| 1803 | ReportCurrentBSSChanged(wpa_supplicant::kCurrentBSSNull); |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 1804 | EXPECT_EQ(Service::kStateIdle, service->state()); |
| 1805 | EXPECT_TRUE(service->IsFailed()); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1806 | EXPECT_EQ(NULL, GetCurrentService().get()); |
| 1807 | EXPECT_EQ(NULL, GetPendingService().get()); |
| 1808 | } |
| 1809 | |
| 1810 | TEST_F(WiFiMainTest, CurrentBSSChangeConnectedToConnectedNewService) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1811 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 1812 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _, _, _)).Times(AnyNumber()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1813 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(AnyNumber()); |
| 1814 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1815 | WiFiEndpointRefPtr ap1 = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 1816 | WiFiEndpointRefPtr ap2 = MakeEndpoint("another_ssid", "01:02:03:04:05:06"); |
| 1817 | WiFiServiceRefPtr service1 = CreateServiceForEndpoint(*ap1); |
| 1818 | WiFiServiceRefPtr service2 = CreateServiceForEndpoint(*ap2); |
| 1819 | |
| 1820 | // Note that the BSS handles used in this test ("ap1", "ap2") are |
| 1821 | // not intended to reflect the format used by supplicant. They're |
| 1822 | // just convenient for testing. |
| 1823 | |
| 1824 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1825 | ReportBSS("ap1", ap1->ssid_string(), ap1->bssid_string(), 0, 0, |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1826 | kNetworkModeInfrastructure); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1827 | ReportBSS("ap2", ap2->ssid_string(), ap2->bssid_string(), 0, 0, |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1828 | kNetworkModeInfrastructure); |
| 1829 | InitiateConnect(service1); |
| 1830 | ReportCurrentBSSChanged("ap1"); |
| 1831 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 1832 | EXPECT_EQ(service1.get(), GetCurrentService().get()); |
| 1833 | |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 1834 | // Note that we deliberately omit intermediate supplicant states |
| 1835 | // (e.g. kInterfaceStateAssociating), on the theory that they are |
| 1836 | // unreliable. Specifically, they may be quashed if the association |
| 1837 | // completes before supplicant flushes its changed properties. |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1838 | ReportCurrentBSSChanged("ap2"); |
| 1839 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 1840 | EXPECT_EQ(service2.get(), GetCurrentService().get()); |
| 1841 | EXPECT_EQ(Service::kStateIdle, service1->state()); |
| 1842 | EXPECT_EQ(Service::kStateConfiguring, service2->state()); |
| 1843 | } |
| 1844 | |
| 1845 | TEST_F(WiFiMainTest, CurrentBSSChangeDisconnectedToConnected) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1846 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
| 1847 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 1848 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _, _, _)).Times(AnyNumber()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1849 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(AnyNumber()); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1850 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 1851 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 1852 | |
| 1853 | // Note that the BSS handle used in this test ("an_ap") is not |
| 1854 | // intended to reflect the format used by supplicant. It's just |
| 1855 | // convenient for testing. |
| 1856 | |
| 1857 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1858 | ReportBSS("an_ap", ap->ssid_string(), ap->bssid_string(), 0, 0, |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1859 | kNetworkModeInfrastructure); |
| 1860 | InitiateConnect(service); |
| 1861 | ReportCurrentBSSChanged("an_ap"); |
| 1862 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 1863 | EXPECT_EQ(service.get(), GetCurrentService().get()); |
| 1864 | EXPECT_EQ(Service::kStateConfiguring, service->state()); |
| 1865 | } |
| 1866 | |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1867 | TEST_F(WiFiMainTest, CurrentBSSChangedUpdateServiceEndpoint) { |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 1868 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
| 1869 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
| 1870 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
| 1871 | |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1872 | const uint16 frequency1 = 2412; |
| 1873 | const uint16 frequency2 = 2442; |
| 1874 | StartWiFi(); |
| 1875 | ReportBSS("bss1", "ssid1", "00:00:00:00:00:01", 1, frequency1, |
| 1876 | kNetworkModeInfrastructure); |
| 1877 | ReportBSS("bss2", "ssid1", "00:00:00:00:00:02", 1, frequency2, |
| 1878 | kNetworkModeInfrastructure); |
| 1879 | EXPECT_EQ(1, GetServices().size()); |
| 1880 | WiFiService *service(GetServices()[0].get()); |
| 1881 | InitiateConnect(service); |
| 1882 | ReportCurrentBSSChanged("bss1"); |
| 1883 | EXPECT_EQ(frequency1, service->frequency_); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 1884 | EXPECT_EQ("00:00:00:00:00:01", service->bssid_); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1885 | ReportCurrentBSSChanged("bss2"); |
| 1886 | EXPECT_EQ(frequency2, service->frequency_); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 1887 | EXPECT_EQ("00:00:00:00:00:02", service->bssid_); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1888 | } |
| 1889 | |
mukesh agrawal | 4eb4d78 | 2011-12-05 17:34:37 +0000 | [diff] [blame] | 1890 | TEST_F(WiFiMainTest, ConfiguredServiceRegistration) { |
| 1891 | Error e; |
| 1892 | EXPECT_CALL(*manager(), RegisterService(_)) |
| 1893 | .Times(0); |
| 1894 | EXPECT_CALL(*manager(), HasService(_)) |
| 1895 | .WillOnce(Return(false)); |
| 1896 | GetOpenService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, &e); |
| 1897 | EXPECT_CALL(*manager(), RegisterService(_)); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1898 | ReportBSS("ap0", "an_ssid", "00:00:00:00:00:00", 0, 0, |
mukesh agrawal | 4eb4d78 | 2011-12-05 17:34:37 +0000 | [diff] [blame] | 1899 | kNetworkModeInfrastructure); |
| 1900 | } |
| 1901 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1902 | TEST_F(WiFiMainTest, NewConnectPreemptsPending) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1903 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
| 1904 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1905 | WiFiEndpointRefPtr ap1 = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 1906 | WiFiEndpointRefPtr ap2 = MakeEndpoint("another_ssid", "01:02:03:04:05:06"); |
| 1907 | WiFiServiceRefPtr service1 = CreateServiceForEndpoint(*ap1); |
| 1908 | WiFiServiceRefPtr service2 = CreateServiceForEndpoint(*ap2); |
| 1909 | |
| 1910 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1911 | ReportBSS("ap1", ap1->ssid_string(), ap1->bssid_string(), 0, 0, |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1912 | kNetworkModeInfrastructure); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1913 | ReportBSS("ap2", ap2->ssid_string(), ap2->bssid_string(), 0, 0, |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1914 | kNetworkModeInfrastructure); |
| 1915 | InitiateConnect(service1); |
| 1916 | EXPECT_EQ(service1.get(), GetPendingService().get()); |
| 1917 | |
| 1918 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Disconnect()); |
| 1919 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), AddNetwork(_)); |
| 1920 | InitiateConnect(service2); |
| 1921 | EXPECT_EQ(service2.get(), GetPendingService().get()); |
| 1922 | } |
| 1923 | |
| 1924 | TEST_F(WiFiMainTest, IsIdle) { |
| 1925 | StartWiFi(); |
| 1926 | EXPECT_TRUE(wifi()->IsIdle()); |
| 1927 | |
| 1928 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 1929 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 1930 | Error error; |
| 1931 | service->AddEndpoint(ap); |
| 1932 | service->AutoConnect(); |
| 1933 | EXPECT_FALSE(wifi()->IsIdle()); |
| 1934 | } |
| 1935 | |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 1936 | MATCHER_P(WiFiAddedArgs, bgscan, "") { |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 1937 | return ContainsKey(arg, wpa_supplicant::kNetworkPropertyScanSSID) && |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 1938 | ContainsKey(arg, wpa_supplicant::kNetworkPropertyBgscan) == bgscan; |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | TEST_F(WiFiMainTest, AddNetworkArgs) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1942 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 1943 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1944 | *supplicant_interface_proxy_; |
| 1945 | |
| 1946 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1947 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 1948 | WiFiService *service(GetServices().begin()->get()); |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 1949 | EXPECT_CALL(supplicant_interface_proxy, AddNetwork(WiFiAddedArgs(true))); |
| 1950 | EXPECT_TRUE(SetBgscanMethod(wpa_supplicant::kNetworkBgscanMethodSimple)); |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 1951 | InitiateConnect(service); |
| 1952 | } |
| 1953 | |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 1954 | TEST_F(WiFiMainTest, AddNetworkArgsNoBgscan) { |
| 1955 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
| 1956 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1957 | *supplicant_interface_proxy_; |
| 1958 | |
| 1959 | StartWiFi(); |
| 1960 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 1961 | WiFiService *service(GetServices().begin()->get()); |
| 1962 | EXPECT_CALL(supplicant_interface_proxy, AddNetwork(WiFiAddedArgs(false))); |
| 1963 | InitiateConnect(service); |
| 1964 | } |
| 1965 | |
| 1966 | TEST_F(WiFiMainTest, AppendBgscan) { |
| 1967 | StartWiFi(); |
| 1968 | WiFiEndpointRefPtr ap1 = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 1969 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap1); |
| 1970 | service->AddEndpoint(ap1); |
| 1971 | EXPECT_EQ(1, service->GetEndpointCount()); |
| 1972 | { |
| 1973 | // 1 endpoint, default bgscan method -- background scan disabled. |
| 1974 | std::map<std::string, DBus::Variant> params; |
| 1975 | AppendBgscan(service.get(), ¶ms); |
| 1976 | EXPECT_FALSE(ContainsKey(params, wpa_supplicant::kNetworkPropertyBgscan)); |
| 1977 | } |
| 1978 | WiFiEndpointRefPtr ap2 = MakeEndpoint("an_ssid", "01:02:03:04:05:06"); |
| 1979 | service->AddEndpoint(ap2); |
| 1980 | EXPECT_EQ(2, service->GetEndpointCount()); |
| 1981 | { |
| 1982 | // 2 endpoints, default bgscan method -- background scan frequency reduced. |
| 1983 | map<string, DBus::Variant> params; |
| 1984 | AppendBgscan(service.get(), ¶ms); |
| 1985 | string config_string; |
| 1986 | EXPECT_TRUE( |
| 1987 | DBusProperties::GetString(params, |
| 1988 | wpa_supplicant::kNetworkPropertyBgscan, |
| 1989 | &config_string)); |
| 1990 | vector<string> elements; |
| 1991 | base::SplitString(config_string, ':', &elements); |
| 1992 | ASSERT_EQ(4, elements.size()); |
| 1993 | EXPECT_EQ(WiFi::kDefaultBgscanMethod, elements[0]); |
| 1994 | EXPECT_EQ(StringPrintf("%d", WiFi::kBackgroundScanIntervalSeconds), |
| 1995 | elements[3]); |
| 1996 | } |
| 1997 | { |
| 1998 | // Explicit bgscan method -- regular background scan frequency. |
| 1999 | EXPECT_TRUE(SetBgscanMethod(wpa_supplicant::kNetworkBgscanMethodSimple)); |
| 2000 | std::map<std::string, DBus::Variant> params; |
| 2001 | AppendBgscan(service.get(), ¶ms); |
| 2002 | string config_string; |
| 2003 | EXPECT_TRUE( |
| 2004 | DBusProperties::GetString(params, |
| 2005 | wpa_supplicant::kNetworkPropertyBgscan, |
| 2006 | &config_string)); |
| 2007 | vector<string> elements; |
| 2008 | base::SplitString(config_string, ':', &elements); |
| 2009 | ASSERT_EQ(4, elements.size()); |
| 2010 | EXPECT_EQ(StringPrintf("%d", WiFi::kDefaultScanIntervalSeconds), |
| 2011 | elements[3]); |
| 2012 | } |
Christopher Wiley | 5c929e2 | 2012-07-16 14:06:04 -0700 | [diff] [blame] | 2013 | { |
| 2014 | // No scan method, simply returns without appending properties |
| 2015 | EXPECT_TRUE(SetBgscanMethod(wpa_supplicant::kNetworkBgscanMethodNone)); |
| 2016 | std::map<std::string, DBus::Variant> params; |
| 2017 | AppendBgscan(service.get(), ¶ms); |
| 2018 | string config_string; |
| 2019 | EXPECT_FALSE( |
| 2020 | DBusProperties::GetString(params, |
| 2021 | wpa_supplicant::kNetworkPropertyBgscan, |
| 2022 | &config_string)); |
| 2023 | } |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 2024 | } |
| 2025 | |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 2026 | TEST_F(WiFiMainTest, StateAndIPIgnoreLinkEvent) { |
| 2027 | StartWiFi(); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 2028 | MockWiFiServiceRefPtr service = MakeMockService(flimflam::kSecurityNone); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 2029 | InitiateConnect(service); |
| 2030 | EXPECT_CALL(*service.get(), SetState(_)).Times(0); |
| 2031 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(0); |
| 2032 | ReportLinkUp(); |
| 2033 | |
| 2034 | // Verify expectations now, because WiFi may cause |service| state |
| 2035 | // changes during TearDown(). |
| 2036 | Mock::VerifyAndClearExpectations(service); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 2037 | EXPECT_CALL(*service.get(), SetState(_)).Times(AnyNumber()); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | TEST_F(WiFiMainTest, SupplicantCompleted) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 2041 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 2042 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _, _, _)).Times(AnyNumber()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 2043 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 2044 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 2045 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 2046 | |
| 2047 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 2048 | ReportBSS("ap", ap->ssid_string(), ap->bssid_string(), 0, 0, |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 2049 | kNetworkModeInfrastructure); |
| 2050 | InitiateConnect(service); |
| 2051 | |
| 2052 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()); |
| 2053 | ReportCurrentBSSChanged("ap"); |
| 2054 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 2055 | EXPECT_EQ(Service::kStateConfiguring, service->state()); |
| 2056 | } |
| 2057 | |
| 2058 | TEST_F(WiFiMainTest, SupplicantCompletedAlreadyConnected) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 2059 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()); |
| 2060 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
| 2061 | EXPECT_CALL(*device_info(), FlushAddresses(_)).Times(AnyNumber()); |
| 2062 | EXPECT_CALL(*manager(), device_info()).Times(AnyNumber()); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 2063 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _, _, _)).Times(AnyNumber()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 2064 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 2065 | EXPECT_CALL(*manager(), IsPortalDetectionEnabled(_)).Times(AnyNumber()); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 2066 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 2067 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 2068 | |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 2069 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 2070 | ReportBSS("ap", ap->ssid_string(), ap->bssid_string(), 0, 0, |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 2071 | kNetworkModeInfrastructure); |
| 2072 | InitiateConnect(service); |
| 2073 | ReportCurrentBSSChanged("ap"); |
| 2074 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
Christopher Wiley | 8f81e2a | 2012-10-17 16:51:32 -0700 | [diff] [blame] | 2075 | Mock::VerifyAndClearExpectations(dhcp_config_.get()); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 2076 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(0); |
Christopher Wiley | 8f81e2a | 2012-10-17 16:51:32 -0700 | [diff] [blame] | 2077 | // Simulate a rekeying event from the AP. These show as transitions from |
| 2078 | // completed->completed from wpa_supplicant. |
| 2079 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 2080 | ReportIPConfigComplete(); |
| 2081 | // Similarly, rekeying events after we have an IP don't trigger L3 |
| 2082 | // configuration. |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 2083 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 2084 | } |
| 2085 | |
Paul Stewart | 66c8600 | 2012-01-30 18:00:52 -0800 | [diff] [blame] | 2086 | TEST_F(WiFiMainTest, ClearCachedCredentials) { |
Paul Stewart | f48eca4 | 2012-10-11 12:10:02 -0700 | [diff] [blame] | 2087 | { |
| 2088 | ClearCachedCredentials(); |
| 2089 | ScopedMockLog log; |
| 2090 | EXPECT_CALL(log, Log(_, _, EndsWith("supplicant proxy is NULL."))); |
| 2091 | // Also expect no crash due to supplicant interface proxy being NULL. |
| 2092 | dispatcher_.DispatchPendingEvents(); |
| 2093 | } |
| 2094 | |
Paul Stewart | 66c8600 | 2012-01-30 18:00:52 -0800 | [diff] [blame] | 2095 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 2096 | *supplicant_interface_proxy_; |
| 2097 | |
| 2098 | StartWiFi(); |
| 2099 | |
| 2100 | // Ensure call to the proxy is deferred. |
| 2101 | EXPECT_CALL(supplicant_interface_proxy, ClearCachedCredentials()) |
| 2102 | .Times(0); |
| 2103 | ClearCachedCredentials(); |
| 2104 | |
| 2105 | Mock::VerifyAndClearExpectations(&supplicant_interface_proxy); |
| 2106 | |
| 2107 | EXPECT_CALL(supplicant_interface_proxy, ClearCachedCredentials()) |
| 2108 | .Times(1); |
| 2109 | dispatcher_.DispatchPendingEvents(); |
| 2110 | |
| 2111 | Mock::VerifyAndClearExpectations(&supplicant_interface_proxy); |
| 2112 | |
| 2113 | EXPECT_CALL(supplicant_interface_proxy, ClearCachedCredentials()) |
| 2114 | .Times(0); |
| 2115 | ClearCachedCredentials(); |
| 2116 | ClearCachedCredentials(); |
| 2117 | |
| 2118 | Mock::VerifyAndClearExpectations(&supplicant_interface_proxy); |
| 2119 | |
| 2120 | // Ensure multiple calls to ClearCachedCredentials() results in only |
| 2121 | // one call to the proxy. |
| 2122 | EXPECT_CALL(supplicant_interface_proxy, ClearCachedCredentials()) |
| 2123 | .Times(1); |
| 2124 | dispatcher_.DispatchPendingEvents(); |
| 2125 | } |
| 2126 | |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 2127 | TEST_F(WiFiMainTest, BSSAddedCreatesBSSProxy) { |
| 2128 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
| 2129 | // TODO(quiche): Consider using a factory for WiFiEndpoints, so that |
| 2130 | // we can test the interaction between WiFi and WiFiEndpoint. (Right |
| 2131 | // now, we're testing across multiple layers.) |
| 2132 | EXPECT_CALL(*supplicant_bss_proxy_, Die()).Times(AnyNumber()); |
| 2133 | EXPECT_CALL(*proxy_factory(), CreateSupplicantBSSProxy(_, _, _)); |
| 2134 | StartWiFi(); |
| 2135 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 2136 | } |
| 2137 | |
| 2138 | TEST_F(WiFiMainTest, BSSRemovedDestroysBSSProxy) { |
| 2139 | // TODO(quiche): As for BSSAddedCreatesBSSProxy, consider using a |
| 2140 | // factory for WiFiEndpoints. |
| 2141 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
| 2142 | |
| 2143 | // Get the pointer before we transfer ownership. |
| 2144 | MockSupplicantBSSProxy *proxy = supplicant_bss_proxy_.get(); |
| 2145 | EXPECT_CALL(*proxy, Die()); |
| 2146 | StartWiFi(); |
| 2147 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 2148 | RemoveBSS("bss0"); |
| 2149 | // Check this now, to make sure RemoveBSS killed the proxy (rather |
| 2150 | // than TearDown). |
| 2151 | Mock::VerifyAndClearExpectations(proxy); |
| 2152 | } |
| 2153 | |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 2154 | TEST_F(WiFiMainTest, FlushBSSOnResume) { |
| 2155 | const struct timeval resume_time = {1, 0}; |
| 2156 | const struct timeval scan_done_time = {6, 0}; |
| 2157 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 2158 | *supplicant_interface_proxy_; |
| 2159 | |
| 2160 | StartWiFi(); |
| 2161 | |
| 2162 | EXPECT_CALL(time_, GetTimeMonotonic(_)) |
| 2163 | .WillOnce(DoAll(SetArgumentPointee<0>(resume_time), Return(0))) |
| 2164 | .WillOnce(DoAll(SetArgumentPointee<0>(scan_done_time), Return(0))); |
| 2165 | EXPECT_CALL(supplicant_interface_proxy, |
| 2166 | FlushBSS(WiFi::kMaxBSSResumeAgeSeconds + 5)); |
mukesh agrawal | 2f9df4e | 2012-08-08 12:29:20 -0700 | [diff] [blame] | 2167 | OnAfterResume(); |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 2168 | ReportScanDone(); |
| 2169 | } |
| 2170 | |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 2171 | TEST_F(WiFiMainTest, ScanTimerIdle) { |
| 2172 | StartWiFi(); |
| 2173 | dispatcher_.DispatchPendingEvents(); |
| 2174 | ReportScanDone(); |
| 2175 | CancelScanTimer(); |
| 2176 | EXPECT_TRUE(GetScanTimer().IsCancelled()); |
| 2177 | |
| 2178 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Scan(_)); |
| 2179 | FireScanTimer(); |
| 2180 | dispatcher_.DispatchPendingEvents(); |
| 2181 | EXPECT_FALSE(GetScanTimer().IsCancelled()); // Automatically re-armed. |
| 2182 | } |
| 2183 | |
| 2184 | TEST_F(WiFiMainTest, ScanTimerScanning) { |
| 2185 | StartWiFi(); |
| 2186 | dispatcher_.DispatchPendingEvents(); |
| 2187 | CancelScanTimer(); |
| 2188 | EXPECT_TRUE(GetScanTimer().IsCancelled()); |
| 2189 | |
| 2190 | // Should not call Scan, since we're already scanning. |
| 2191 | // (Scanning is triggered by StartWiFi.) |
| 2192 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Scan(_)).Times(0); |
| 2193 | FireScanTimer(); |
| 2194 | dispatcher_.DispatchPendingEvents(); |
| 2195 | EXPECT_FALSE(GetScanTimer().IsCancelled()); // Automatically re-armed. |
| 2196 | } |
| 2197 | |
| 2198 | TEST_F(WiFiMainTest, ScanTimerConnecting) { |
| 2199 | StartWiFi(); |
| 2200 | dispatcher_.DispatchPendingEvents(); |
| 2201 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 2202 | ReportScanDone(); |
| 2203 | WiFiService *service(GetServices().begin()->get()); |
| 2204 | InitiateConnect(service); |
| 2205 | CancelScanTimer(); |
| 2206 | EXPECT_TRUE(GetScanTimer().IsCancelled()); |
| 2207 | |
| 2208 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Scan(_)).Times(0); |
| 2209 | FireScanTimer(); |
| 2210 | dispatcher_.DispatchPendingEvents(); |
| 2211 | EXPECT_FALSE(GetScanTimer().IsCancelled()); // Automatically re-armed. |
| 2212 | } |
| 2213 | |
| 2214 | TEST_F(WiFiMainTest, ScanTimerReconfigured) { |
| 2215 | StartWiFi(); |
| 2216 | CancelScanTimer(); |
| 2217 | EXPECT_TRUE(GetScanTimer().IsCancelled()); |
| 2218 | |
| 2219 | SetScanInterval(1); |
| 2220 | EXPECT_FALSE(GetScanTimer().IsCancelled()); |
| 2221 | } |
| 2222 | |
| 2223 | TEST_F(WiFiMainTest, ScanTimerResetOnScanDone) { |
| 2224 | StartWiFi(); |
| 2225 | CancelScanTimer(); |
| 2226 | EXPECT_TRUE(GetScanTimer().IsCancelled()); |
| 2227 | |
| 2228 | ReportScanDone(); |
| 2229 | EXPECT_FALSE(GetScanTimer().IsCancelled()); |
| 2230 | } |
| 2231 | |
| 2232 | TEST_F(WiFiMainTest, ScanTimerStopOnZeroInterval) { |
| 2233 | StartWiFi(); |
| 2234 | EXPECT_FALSE(GetScanTimer().IsCancelled()); |
| 2235 | |
| 2236 | SetScanInterval(0); |
| 2237 | EXPECT_TRUE(GetScanTimer().IsCancelled()); |
| 2238 | } |
| 2239 | |
| 2240 | TEST_F(WiFiMainTest, ScanOnDisconnectWithHidden) { |
| 2241 | Error e; |
| 2242 | scoped_refptr<MockProfile> profile( |
| 2243 | new NiceMock<MockProfile>(control_interface(), manager(), "")); |
| 2244 | WiFiServiceRefPtr hidden_service = |
| 2245 | GetServiceInner(flimflam::kTypeWifi, "hidden_ssid", |
| 2246 | flimflam::kModeManaged, NULL, NULL, true, &e); |
| 2247 | hidden_service->set_profile(profile); |
| 2248 | |
| 2249 | StartWiFi(); |
| 2250 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 2251 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 2252 | ReportBSS("an_ap", ap->ssid_string(), ap->bssid_string(), 0, 0, |
| 2253 | kNetworkModeInfrastructure); |
| 2254 | InitiateConnect(service); |
| 2255 | ReportCurrentBSSChanged("an_ap"); |
| 2256 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 2257 | dispatcher_.DispatchPendingEvents(); |
| 2258 | |
| 2259 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), |
| 2260 | Scan(HasHiddenSSID("hidden_ssid"))); |
| 2261 | ReportCurrentBSSChanged(wpa_supplicant::kCurrentBSSNull); |
| 2262 | dispatcher_.DispatchPendingEvents(); |
| 2263 | } |
| 2264 | |
| 2265 | TEST_F(WiFiMainTest, NoScanOnDisconnectWithoutHidden) { |
| 2266 | StartWiFi(); |
| 2267 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 2268 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 2269 | ReportBSS("an_ap", ap->ssid_string(), ap->bssid_string(), 0, 0, |
| 2270 | kNetworkModeInfrastructure); |
| 2271 | InitiateConnect(service); |
| 2272 | ReportCurrentBSSChanged("an_ap"); |
| 2273 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 2274 | dispatcher_.DispatchPendingEvents(); |
| 2275 | |
| 2276 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Scan(_)).Times(0); |
| 2277 | ReportCurrentBSSChanged(wpa_supplicant::kCurrentBSSNull); |
| 2278 | dispatcher_.DispatchPendingEvents(); |
| 2279 | } |
| 2280 | |
Paul Stewart | 3c508e1 | 2012-08-09 11:40:06 -0700 | [diff] [blame] | 2281 | TEST_F(WiFiMainTest, LinkMonitorFailure) { |
| 2282 | StartWiFi(); |
| 2283 | ScopedMockLog log; |
| 2284 | EXPECT_CALL(log, Log(_, _, _)).Times(AnyNumber()); |
| 2285 | MockLinkMonitor *link_monitor = new StrictMock<MockLinkMonitor>(); |
| 2286 | SetLinkMonitor(link_monitor); |
| 2287 | EXPECT_CALL(*link_monitor, IsGatewayFound()) |
| 2288 | .WillOnce(Return(false)) |
| 2289 | .WillRepeatedly(Return(true)); |
| 2290 | EXPECT_CALL(log, Log(logging::LOG_INFO, _, |
| 2291 | EndsWith("gateway was never found."))).Times(1); |
| 2292 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Reassociate()).Times(0); |
| 2293 | OnLinkMonitorFailure(); |
| 2294 | EXPECT_CALL(log, Log(logging::LOG_INFO, _, |
| 2295 | EndsWith("Called Reassociate()."))).Times(1); |
| 2296 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Reassociate()).Times(1); |
| 2297 | OnLinkMonitorFailure(); |
| 2298 | OnSupplicantVanish(); |
| 2299 | EXPECT_CALL(log, Log(logging::LOG_ERROR, _, |
| 2300 | EndsWith("Cannot reassociate."))).Times(1); |
| 2301 | OnLinkMonitorFailure(); |
| 2302 | } |
| 2303 | |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 2304 | TEST_F(WiFiMainTest, SuspectCredentialsOpen) { |
| 2305 | Error e; |
| 2306 | WiFiServiceRefPtr service = GetOpenService( |
| 2307 | flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, &e); |
| 2308 | ReportStateChanged(wpa_supplicant::kInterfaceState4WayHandshake); |
| 2309 | EXPECT_FALSE(service->has_ever_connected()); |
| 2310 | EXPECT_FALSE(wifi()->SuspectCredentials(*service)); |
| 2311 | } |
| 2312 | |
| 2313 | TEST_F(WiFiMainTest, SuspectCredentialsWPANeverConnected) { |
| 2314 | Error e; |
| 2315 | WiFiServiceRefPtr service = |
| 2316 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 2317 | flimflam::kSecurityWpa, "abcdefgh", &e); |
| 2318 | ReportStateChanged(wpa_supplicant::kInterfaceState4WayHandshake); |
| 2319 | EXPECT_FALSE(service->has_ever_connected()); |
| 2320 | EXPECT_TRUE(wifi()->SuspectCredentials(*service)); |
| 2321 | } |
| 2322 | |
| 2323 | TEST_F(WiFiMainTest, SuspectCredentialsWPAPreviouslyConnected) { |
| 2324 | Error e; |
| 2325 | WiFiServiceRefPtr service = |
| 2326 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 2327 | flimflam::kSecurityWpa, "abcdefgh", &e); |
| 2328 | ReportStateChanged(wpa_supplicant::kInterfaceState4WayHandshake); |
| 2329 | service->has_ever_connected_ = true; |
| 2330 | EXPECT_FALSE(wifi()->SuspectCredentials(*service)); |
| 2331 | } |
| 2332 | |
| 2333 | TEST_F(WiFiMainTest, SuspectCredentialsYieldFailure) { |
| 2334 | ScopedMockLog log; |
| 2335 | Error e; |
| 2336 | MockWiFiServiceRefPtr service = MakeMockService(flimflam::kSecurityWpa); |
| 2337 | SetPendingService(service); |
| 2338 | ReportStateChanged(wpa_supplicant::kInterfaceState4WayHandshake); |
| 2339 | EXPECT_FALSE(service->has_ever_connected()); |
| 2340 | |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 2341 | EXPECT_CALL(*service, SetFailure(Service::kFailureBadPassphrase)); |
mukesh agrawal | 56e3220 | 2012-07-26 16:32:11 -0700 | [diff] [blame] | 2342 | EXPECT_CALL(*service, SetFailureSilent(_)).Times(0); |
| 2343 | EXPECT_CALL(*service, SetState(_)).Times(0); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 2344 | EXPECT_CALL(log, Log(_, _, _)).Times(AnyNumber()); |
| 2345 | EXPECT_CALL(log, Log(logging::LOG_ERROR, _, EndsWith("Bad passphrase?"))); |
| 2346 | ReportCurrentBSSChanged(wpa_supplicant::kCurrentBSSNull); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 2347 | } |
| 2348 | |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 2349 | // Scanning tests will use a mock of the event dispatcher instead of a real |
| 2350 | // one. |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 2351 | class WiFiTimerTest : public WiFiObjectTest { |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 2352 | public: |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 2353 | WiFiTimerTest() : WiFiObjectTest(&mock_dispatcher_) {} |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 2354 | |
| 2355 | protected: |
| 2356 | void ExpectInitialScanSequence(); |
| 2357 | |
| 2358 | StrictMock<MockEventDispatcher> mock_dispatcher_; |
| 2359 | }; |
| 2360 | |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 2361 | void WiFiTimerTest::ExpectInitialScanSequence() { |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 2362 | // Choose a number of iterations some multiple higher than the fast scan |
| 2363 | // count. |
| 2364 | const int kScanTimes = WiFi::kNumFastScanAttempts * 4; |
| 2365 | |
| 2366 | // Each time we call FireScanTimer() below, WiFi will post a task to actually |
| 2367 | // run Scan() on the wpa_supplicant proxy. |
| 2368 | EXPECT_CALL(mock_dispatcher_, PostTask(_)) |
| 2369 | .Times(kScanTimes); |
| 2370 | { |
| 2371 | InSequence seq; |
| 2372 | // The scans immediately after the initial scan should happen at the short |
| 2373 | // interval. If we add the initial scan (not invoked in this function) to |
| 2374 | // the ones in the expectation below, we get WiFi::kNumFastScanAttempts at |
| 2375 | // the fast scan interval. |
| 2376 | EXPECT_CALL(mock_dispatcher_, PostDelayedTask( |
| 2377 | _, WiFi::kFastScanIntervalSeconds * 1000)) |
| 2378 | .Times(WiFi::kNumFastScanAttempts - 1) |
| 2379 | .WillRepeatedly(Return(true)); |
| 2380 | |
| 2381 | // After this, the WiFi device should use the normal scan interval. |
| 2382 | EXPECT_CALL(mock_dispatcher_, PostDelayedTask( |
| 2383 | _, GetScanInterval() * 1000)) |
| 2384 | .Times(kScanTimes - WiFi::kNumFastScanAttempts + 1) |
| 2385 | .WillRepeatedly(Return(true)); |
| 2386 | |
| 2387 | for (int i = 0; i < kScanTimes; i++) { |
| 2388 | FireScanTimer(); |
| 2389 | } |
| 2390 | } |
| 2391 | } |
| 2392 | |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 2393 | TEST_F(WiFiTimerTest, FastRescan) { |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 2394 | // This PostTask is a result of the call to Scan(NULL), and is meant to |
| 2395 | // post a task to call Scan() on the wpa_supplicant proxy immediately. |
| 2396 | EXPECT_CALL(mock_dispatcher_, PostTask(_)); |
| 2397 | EXPECT_CALL(mock_dispatcher_, PostDelayedTask( |
| 2398 | _, WiFi::kFastScanIntervalSeconds * 1000)) |
| 2399 | .WillOnce(Return(true)); |
| 2400 | StartWiFi(); |
| 2401 | |
| 2402 | ExpectInitialScanSequence(); |
| 2403 | |
| 2404 | // If we end up disconnecting, the sequence should repeat. |
| 2405 | EXPECT_CALL(mock_dispatcher_, PostDelayedTask( |
| 2406 | _, WiFi::kFastScanIntervalSeconds * 1000)) |
| 2407 | .WillOnce(Return(true)); |
| 2408 | RestartFastScanAttempts(); |
| 2409 | |
| 2410 | ExpectInitialScanSequence(); |
| 2411 | } |
| 2412 | |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 2413 | TEST_F(WiFiTimerTest, ReconnectTimer) { |
| 2414 | EXPECT_CALL(mock_dispatcher_, PostTask(_)).Times(AnyNumber()); |
| 2415 | EXPECT_CALL(mock_dispatcher_, PostDelayedTask(_, _)).Times(AnyNumber()); |
| 2416 | SetupConnectedService(DBus::Path()); |
| 2417 | Mock::VerifyAndClearExpectations(&mock_dispatcher_); |
| 2418 | |
| 2419 | EXPECT_CALL(mock_dispatcher_, PostDelayedTask( |
| 2420 | _, GetReconnectTimeoutSeconds() * 1000)).Times(1); |
| 2421 | StartReconnectTimer(); |
| 2422 | Mock::VerifyAndClearExpectations(&mock_dispatcher_); |
| 2423 | StopReconnectTimer(); |
| 2424 | |
| 2425 | EXPECT_CALL(mock_dispatcher_, PostDelayedTask( |
| 2426 | _, GetReconnectTimeoutSeconds() * 1000)).Times(1); |
| 2427 | StartReconnectTimer(); |
| 2428 | Mock::VerifyAndClearExpectations(&mock_dispatcher_); |
| 2429 | GetReconnectTimeoutCallback().callback().Run(); |
| 2430 | |
| 2431 | EXPECT_CALL(mock_dispatcher_, PostDelayedTask( |
| 2432 | _, GetReconnectTimeoutSeconds() * 1000)).Times(1); |
| 2433 | StartReconnectTimer(); |
| 2434 | Mock::VerifyAndClearExpectations(&mock_dispatcher_); |
| 2435 | |
| 2436 | EXPECT_CALL(mock_dispatcher_, PostDelayedTask( |
| 2437 | _, GetReconnectTimeoutSeconds() * 1000)).Times(0); |
| 2438 | StartReconnectTimer(); |
| 2439 | } |
| 2440 | |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 2441 | TEST_F(WiFiMainTest, EAPCertification) { |
| 2442 | MockWiFiServiceRefPtr service = MakeMockService(flimflam::kSecurity8021x); |
| 2443 | EXPECT_CALL(*service, AddEAPCertification(_, _)).Times(0); |
| 2444 | |
| 2445 | ScopedMockLog log; |
| 2446 | EXPECT_CALL(log, Log(logging::LOG_ERROR, _, EndsWith("no current service."))); |
| 2447 | map<string, ::DBus::Variant> args; |
| 2448 | ReportCertification(args); |
| 2449 | Mock::VerifyAndClearExpectations(&log); |
| 2450 | |
| 2451 | SetCurrentService(service); |
| 2452 | EXPECT_CALL(log, Log(logging::LOG_ERROR, _, EndsWith("no depth parameter."))); |
| 2453 | ReportCertification(args); |
| 2454 | Mock::VerifyAndClearExpectations(&log); |
| 2455 | |
| 2456 | const uint32 kDepth = 123; |
| 2457 | args[wpa_supplicant::kInterfacePropertyDepth].writer().append_uint32(kDepth); |
| 2458 | |
| 2459 | EXPECT_CALL(log, |
| 2460 | Log(logging::LOG_ERROR, _, EndsWith("no subject parameter."))); |
| 2461 | ReportCertification(args); |
| 2462 | Mock::VerifyAndClearExpectations(&log); |
| 2463 | |
| 2464 | const string kSubject("subject"); |
| 2465 | args[wpa_supplicant::kInterfacePropertySubject].writer() |
| 2466 | .append_string(kSubject.c_str()); |
| 2467 | EXPECT_CALL(*service, AddEAPCertification(kSubject, kDepth)).Times(1); |
| 2468 | ReportCertification(args); |
| 2469 | } |
| 2470 | |
mukesh agrawal | c4f368f | 2012-06-04 19:45:52 -0700 | [diff] [blame] | 2471 | TEST_F(WiFiMainTest, PendingScanDoesNotCrashAfterStop) { |
| 2472 | // Scan is one task that should be skipped after Stop. Others are |
| 2473 | // skipped by the same mechanism (invalidating weak pointers), so we |
| 2474 | // don't test them individually. |
| 2475 | // |
| 2476 | // Note that we can't test behavior by setting expectations on the |
| 2477 | // supplicant_interface_proxy_, since that is destroyed when we StopWiFi(). |
| 2478 | StartWiFi(); |
| 2479 | StopWiFi(); |
| 2480 | dispatcher_.DispatchPendingEvents(); |
| 2481 | } |
| 2482 | |
Darin Petkov | 60ceaf3 | 2012-10-18 10:36:01 +0200 | [diff] [blame] | 2483 | TEST_F(WiFiMainTest, VerifyPaths) { |
| 2484 | string path = WiFi::kSupplicantConfPath; |
| 2485 | TrimString(path, FilePath::kSeparators, &path); |
| 2486 | EXPECT_TRUE(file_util::PathExists(FilePath(SYSROOT).Append(path))); |
| 2487 | } |
| 2488 | |
Gaurav Shah | 6d2c72d | 2012-10-16 16:30:44 -0700 | [diff] [blame] | 2489 | struct BSS { |
| 2490 | string bsspath; |
| 2491 | string ssid; |
| 2492 | string bssid; |
| 2493 | int16_t signal_strength; |
| 2494 | uint16 frequency; |
| 2495 | const char* mode; |
| 2496 | }; |
| 2497 | |
| 2498 | TEST_F(WiFiMainTest, GetGeolocationObjects) { |
| 2499 | BSS bsses[] = { |
| 2500 | {"bssid1", "ssid1", "00:00:00:00:00:00", 5, Metrics::kWiFiFrequency2412, |
| 2501 | kNetworkModeInfrastructure}, |
| 2502 | {"bssid2", "ssid2", "01:00:00:00:00:00", 30, Metrics::kWiFiFrequency5170, |
| 2503 | kNetworkModeInfrastructure}, |
| 2504 | // Same SSID but different BSSID is an additional geolocation object. |
| 2505 | {"bssid3", "ssid1", "02:00:00:00:00:00", 100, 0, |
| 2506 | kNetworkModeInfrastructure} |
| 2507 | }; |
| 2508 | StartWiFi(); |
| 2509 | vector<GeolocationInfo> objects; |
| 2510 | EXPECT_EQ(objects.size(), 0); |
| 2511 | |
| 2512 | for (size_t i = 0; i < arraysize(bsses); ++i) { |
| 2513 | ReportBSS(bsses[i].bsspath, bsses[i].ssid, bsses[i].bssid, |
| 2514 | bsses[i].signal_strength, bsses[i].frequency, bsses[i].mode); |
| 2515 | objects = wifi()->GetGeolocationObjects(); |
| 2516 | EXPECT_EQ(objects.size(), i + 1); |
| 2517 | |
| 2518 | GeolocationInfo expected_info; |
| 2519 | expected_info.AddField(kGeoMacAddressProperty, bsses[i].bssid); |
| 2520 | expected_info.AddField(kGeoSignalStrengthProperty, |
| 2521 | StringPrintf("%d", bsses[i].signal_strength)); |
| 2522 | expected_info.AddField(kGeoChannelProperty, StringPrintf( |
| 2523 | "%d", Metrics::WiFiFrequencyToChannel(bsses[i].frequency))); |
| 2524 | EXPECT_TRUE(objects[i].Equals(expected_info)); |
| 2525 | }; |
| 2526 | }; |
| 2527 | |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 2528 | } // namespace shill |