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"))); |
| 780 | EXPECT_CALL(*supplicant_interface_proxy_, Scan(_)); |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 781 | EXPECT_TRUE(GetScanTimer().IsCancelled()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 782 | StartWiFi(); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 783 | dispatcher_.DispatchPendingEvents(); |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 784 | EXPECT_FALSE(GetScanTimer().IsCancelled()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 785 | } |
| 786 | |
Ben Chan | 381fdcc | 2012-10-14 21:10:36 -0700 | [diff] [blame] | 787 | TEST_F(WiFiMainTest, RemoveNetwork) { |
| 788 | DBus::Path network = "/test/path"; |
| 789 | EXPECT_CALL(*supplicant_interface_proxy_, RemoveNetwork(network)); |
| 790 | StartWiFi(); |
| 791 | EXPECT_TRUE(RemoveNetwork(network)); |
| 792 | } |
| 793 | |
| 794 | TEST_F(WiFiMainTest, RemoveNetworkWhenSupplicantReturnsNetworkUnknown) { |
| 795 | DBus::Path network = "/test/path"; |
| 796 | EXPECT_CALL(*supplicant_interface_proxy_, RemoveNetwork(network)) |
| 797 | .WillRepeatedly(Throw( |
| 798 | DBus::Error( |
| 799 | "fi.w1.wpa_supplicant1.NetworkUnknown", |
| 800 | "test threw fi.w1.wpa_supplicant1.NetworkUnknown"))); |
| 801 | StartWiFi(); |
| 802 | EXPECT_TRUE(RemoveNetwork(network)); |
| 803 | } |
| 804 | |
| 805 | TEST_F(WiFiMainTest, RemoveNetworkWhenSupplicantReturnsInvalidArgs) { |
| 806 | DBus::Path network = "/test/path"; |
| 807 | EXPECT_CALL(*supplicant_interface_proxy_, RemoveNetwork(network)) |
| 808 | .WillRepeatedly(Throw( |
| 809 | DBus::Error( |
| 810 | "fi.w1.wpa_supplicant1.InvalidArgs", |
| 811 | "test threw fi.w1.wpa_supplicant1.InvalidArgs"))); |
| 812 | StartWiFi(); |
| 813 | EXPECT_FALSE(RemoveNetwork(network)); |
| 814 | } |
| 815 | |
| 816 | TEST_F(WiFiMainTest, RemoveNetworkWhenSupplicantReturnsUnknownError) { |
| 817 | DBus::Path network = "/test/path"; |
| 818 | EXPECT_CALL(*supplicant_interface_proxy_, RemoveNetwork(network)) |
| 819 | .WillRepeatedly(Throw( |
| 820 | DBus::Error( |
| 821 | "fi.w1.wpa_supplicant1.UnknownError", |
| 822 | "test threw fi.w1.wpa_supplicant1.UnknownError"))); |
| 823 | StartWiFi(); |
| 824 | EXPECT_FALSE(RemoveNetwork(network)); |
| 825 | } |
| 826 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 827 | TEST_F(WiFiMainTest, Restart) { |
| 828 | EXPECT_CALL(*supplicant_process_proxy_, CreateInterface(_)) |
| 829 | .Times(AnyNumber()) |
| 830 | .WillRepeatedly(Throw( |
| 831 | DBus::Error( |
| 832 | "fi.w1.wpa_supplicant1.InterfaceExists", |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 833 | "test threw fi.w1.wpa_supplicant1.InterfaceExists"))); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 834 | EXPECT_CALL(*supplicant_process_proxy_, GetInterface(_)); |
| 835 | EXPECT_CALL(*supplicant_interface_proxy_, Scan(_)); |
| 836 | StartWiFi(); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 837 | dispatcher_.DispatchPendingEvents(); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | TEST_F(WiFiMainTest, StartClearsState) { |
| 841 | EXPECT_CALL(*supplicant_interface_proxy_, RemoveAllNetworks()); |
| 842 | EXPECT_CALL(*supplicant_interface_proxy_, FlushBSS(_)); |
| 843 | StartWiFi(); |
| 844 | } |
| 845 | |
mukesh agrawal | 2f9df4e | 2012-08-08 12:29:20 -0700 | [diff] [blame] | 846 | TEST_F(WiFiMainTest, ResumeStartsScanWhenIdle) { |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 847 | EXPECT_CALL(*supplicant_interface_proxy_, Scan(_)); |
| 848 | StartWiFi(); |
| 849 | dispatcher_.DispatchPendingEvents(); |
| 850 | Mock::VerifyAndClearExpectations(&supplicant_interface_proxy_); |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 851 | ReportScanDone(); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 852 | ASSERT_TRUE(wifi()->IsIdle()); |
| 853 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Scan(_)); |
mukesh agrawal | 2f9df4e | 2012-08-08 12:29:20 -0700 | [diff] [blame] | 854 | OnAfterResume(); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 855 | dispatcher_.DispatchPendingEvents(); |
| 856 | } |
| 857 | |
mukesh agrawal | 2f9df4e | 2012-08-08 12:29:20 -0700 | [diff] [blame] | 858 | TEST_F(WiFiMainTest, SuspendDoesNotStartScan) { |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 859 | EXPECT_CALL(*supplicant_interface_proxy_, Scan(_)); |
| 860 | StartWiFi(); |
| 861 | dispatcher_.DispatchPendingEvents(); |
| 862 | Mock::VerifyAndClearExpectations(&supplicant_interface_proxy_); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 863 | ASSERT_TRUE(wifi()->IsIdle()); |
| 864 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Scan(_)).Times(0); |
mukesh agrawal | 2f9df4e | 2012-08-08 12:29:20 -0700 | [diff] [blame] | 865 | OnBeforeSuspend(); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 866 | dispatcher_.DispatchPendingEvents(); |
| 867 | } |
| 868 | |
mukesh agrawal | 2f9df4e | 2012-08-08 12:29:20 -0700 | [diff] [blame] | 869 | TEST_F(WiFiMainTest, ResumeDoesNotStartScanWhenNotIdle) { |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 870 | EXPECT_CALL(*supplicant_interface_proxy_, Scan(_)); |
| 871 | StartWiFi(); |
| 872 | |
| 873 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 874 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 875 | Error error; |
mukesh agrawal | 3ab56ac | 2012-05-31 14:41:43 -0700 | [diff] [blame] | 876 | ScopedMockLog log; |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 877 | service->AddEndpoint(ap); |
| 878 | service->AutoConnect(); |
| 879 | EXPECT_FALSE(wifi()->IsIdle()); |
| 880 | dispatcher_.DispatchPendingEvents(); |
| 881 | Mock::VerifyAndClearExpectations(&supplicant_interface_proxy_); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 882 | ASSERT_FALSE(wifi()->IsIdle()); |
mukesh agrawal | 3ab56ac | 2012-05-31 14:41:43 -0700 | [diff] [blame] | 883 | EXPECT_CALL(log, Log(_, _, _)).Times(AnyNumber()); |
| 884 | EXPECT_CALL(log, Log(_, _, EndsWith("already scanning or connected."))); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 885 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Scan(_)).Times(0); |
mukesh agrawal | 2f9df4e | 2012-08-08 12:29:20 -0700 | [diff] [blame] | 886 | OnAfterResume(); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 887 | dispatcher_.DispatchPendingEvents(); |
| 888 | } |
| 889 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 890 | TEST_F(WiFiMainTest, ScanResults) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 891 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 892 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 893 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 894 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 895 | "bss1", "ssid1", "00:00:00:00:00:01", 1, 0, kNetworkModeInfrastructure); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 896 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 897 | "bss2", "ssid2", "00:00:00:00:00:02", 2, 0, kNetworkModeInfrastructure); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 898 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 899 | "bss3", "ssid3", "00:00:00:00:00:03", 3, 0, kNetworkModeInfrastructure); |
| 900 | const uint16 frequency = 2412; |
| 901 | ReportBSS("bss4", "ssid4", "00:00:00:00:00:04", 4, frequency, |
| 902 | kNetworkModeAdHoc); |
| 903 | |
| 904 | const WiFi::EndpointMap &endpoints_by_rpcid = GetEndpointMap(); |
| 905 | EXPECT_EQ(5, endpoints_by_rpcid.size()); |
| 906 | |
| 907 | WiFi::EndpointMap::const_iterator i; |
| 908 | WiFiEndpointRefPtr endpoint; |
| 909 | for (i = endpoints_by_rpcid.begin(); |
| 910 | i != endpoints_by_rpcid.end(); |
| 911 | ++i) { |
| 912 | if (i->second->bssid_string() == "00:00:00:00:00:04") |
| 913 | break; |
| 914 | } |
| 915 | ASSERT_TRUE(i != endpoints_by_rpcid.end()); |
| 916 | EXPECT_EQ(4, i->second->signal_strength()); |
| 917 | EXPECT_EQ(frequency, i->second->frequency()); |
| 918 | EXPECT_EQ("adhoc", i->second->network_mode()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | TEST_F(WiFiMainTest, ScanResultsWithUpdates) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 922 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
| 923 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
| 924 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 925 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 926 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 927 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 928 | "bss1", "ssid1", "00:00:00:00:00:01", 1, 0, kNetworkModeInfrastructure); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 929 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 930 | "bss2", "ssid2", "00:00:00:00:00:02", 2, 0, kNetworkModeInfrastructure); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 931 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 932 | "bss1", "ssid1", "00:00:00:00:00:01", 3, 0, kNetworkModeInfrastructure); |
| 933 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 4, 0, kNetworkModeAdHoc); |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 934 | |
| 935 | const WiFi::EndpointMap &endpoints_by_rpcid = GetEndpointMap(); |
| 936 | EXPECT_EQ(3, endpoints_by_rpcid.size()); |
| 937 | |
| 938 | WiFi::EndpointMap::const_iterator i; |
| 939 | WiFiEndpointRefPtr endpoint; |
| 940 | for (i = endpoints_by_rpcid.begin(); |
| 941 | i != endpoints_by_rpcid.end(); |
| 942 | ++i) { |
| 943 | if (i->second->bssid_string() == "00:00:00:00:00:00") |
| 944 | break; |
| 945 | } |
| 946 | ASSERT_TRUE(i != endpoints_by_rpcid.end()); |
| 947 | EXPECT_EQ(4, i->second->signal_strength()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | TEST_F(WiFiMainTest, ScanCompleted) { |
| 951 | StartWiFi(); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 952 | EXPECT_CALL(*manager(), RegisterService(_)) |
| 953 | .Times(3); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 954 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 955 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 956 | "bss1", "ssid1", "00:00:00:00:00:01", 1, 0, kNetworkModeInfrastructure); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 957 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 958 | "bss2", "ssid2", "00:00:00:00:00:02", 2, 0, kNetworkModeInfrastructure); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 959 | ReportScanDone(); |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 960 | EXPECT_EQ(3, GetServices().size()); |
mukesh agrawal | b385761 | 2012-01-18 16:23:29 -0800 | [diff] [blame] | 961 | |
mukesh agrawal | e9adda1 | 2012-02-09 18:33:48 -0800 | [diff] [blame] | 962 | // BSSes with SSIDs that start with NULL should be filtered. |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 963 | 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] | 964 | EXPECT_EQ(3, GetEndpointMap().size()); |
mukesh agrawal | b385761 | 2012-01-18 16:23:29 -0800 | [diff] [blame] | 965 | EXPECT_EQ(3, GetServices().size()); |
| 966 | |
mukesh agrawal | e9adda1 | 2012-02-09 18:33:48 -0800 | [diff] [blame] | 967 | // BSSes with empty SSIDs should be filtered. |
| 968 | ReportBSS("bss3", string(), "00:00:00:00:00:03", 3, 0, kNetworkModeAdHoc); |
| 969 | EXPECT_EQ(3, GetEndpointMap().size()); |
| 970 | EXPECT_EQ(3, GetServices().size()); |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | TEST_F(WiFiMainTest, EndpointGroupingTogether) { |
| 974 | StartWiFi(); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 975 | |
| 976 | InSequence s; |
| 977 | EXPECT_CALL(*manager(), RegisterService(_)); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 978 | EXPECT_CALL(*manager(), HasService(_)); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 979 | EXPECT_CALL(*manager(), UpdateService(_)); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 980 | ReportBSS("bss0", "ssid", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 981 | ReportBSS("bss1", "ssid", "00:00:00:00:00:01", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 982 | ReportScanDone(); |
| 983 | EXPECT_EQ(1, GetServices().size()); |
| 984 | } |
| 985 | |
| 986 | TEST_F(WiFiMainTest, EndpointGroupingDifferentSSID) { |
| 987 | StartWiFi(); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 988 | EXPECT_CALL(*manager(), RegisterService(_)) |
| 989 | .Times(2); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 990 | ReportBSS("bss0", "ssid1", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 991 | ReportBSS("bss1", "ssid2", "00:00:00:00:00:01", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 992 | ReportScanDone(); |
| 993 | EXPECT_EQ(2, GetServices().size()); |
| 994 | } |
| 995 | |
| 996 | TEST_F(WiFiMainTest, EndpointGroupingDifferentMode) { |
| 997 | StartWiFi(); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 998 | EXPECT_CALL(*manager(), RegisterService(_)) |
| 999 | .Times(2); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1000 | ReportBSS("bss0", "ssid", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 1001 | ReportBSS("bss1", "ssid", "00:00:00:00:00:01", 0, 0, |
| 1002 | kNetworkModeInfrastructure); |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 1003 | ReportScanDone(); |
| 1004 | EXPECT_EQ(2, GetServices().size()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 1007 | TEST_F(WiFiMainTest, NonExistentBSSRemoved) { |
| 1008 | // Removal of non-existent BSS should not cause a crash. |
| 1009 | StartWiFi(); |
| 1010 | RemoveBSS("bss0"); |
| 1011 | EXPECT_EQ(0, GetServices().size()); |
| 1012 | } |
| 1013 | |
mukesh agrawal | e9adda1 | 2012-02-09 18:33:48 -0800 | [diff] [blame] | 1014 | TEST_F(WiFiMainTest, BSSWithEmptySSIDRemoved) { |
| 1015 | // Removal of BSS with an empty SSID should not cause a crash. |
| 1016 | ReportBSS("bss", string(), "00:00:00:00:00:01", 0, 0, kNetworkModeAdHoc); |
| 1017 | StartWiFi(); |
| 1018 | RemoveBSS("bss"); |
| 1019 | EXPECT_EQ(0, GetServices().size()); |
| 1020 | } |
| 1021 | |
| 1022 | TEST_F(WiFiMainTest, BSSWithNullSSIDRemoved) { |
| 1023 | // Removal of BSS with a NULL SSID should not cause a crash. |
| 1024 | ReportBSS("bss", string(1, 0), "00:00:00:00:00:01", 0, 0, kNetworkModeAdHoc); |
| 1025 | StartWiFi(); |
| 1026 | RemoveBSS("bss"); |
| 1027 | EXPECT_EQ(0, GetServices().size()); |
| 1028 | } |
| 1029 | |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 1030 | TEST_F(WiFiMainTest, LoneBSSRemoved) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1031 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 1032 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1033 | ReportBSS("bss0", "ssid", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 1034 | ReportScanDone(); |
| 1035 | EXPECT_EQ(1, GetServices().size()); |
| 1036 | EXPECT_TRUE(GetServices().front()->IsVisible()); |
| 1037 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1038 | EXPECT_CALL(*manager(), DeregisterService(_)); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 1039 | RemoveBSS("bss0"); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1040 | EXPECT_TRUE(GetServices().empty()); |
| 1041 | } |
| 1042 | |
| 1043 | TEST_F(WiFiMainTest, LoneBSSRemovedWhileConnected) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1044 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1045 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1046 | ReportBSS("bss0", "ssid", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1047 | ReportScanDone(); |
| 1048 | ReportCurrentBSSChanged("bss0"); |
| 1049 | |
| 1050 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Disconnect()); |
| 1051 | EXPECT_CALL(*manager(), DeregisterService(_)); |
| 1052 | RemoveBSS("bss0"); |
| 1053 | EXPECT_TRUE(GetServices().empty()); |
| 1054 | } |
| 1055 | |
| 1056 | TEST_F(WiFiMainTest, LoneBSSRemovedWhileConnectedToHidden) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1057 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
| 1058 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1059 | StartWiFi(); |
| 1060 | |
| 1061 | Error e; |
| 1062 | WiFiServiceRefPtr service = |
| 1063 | GetServiceInner(flimflam::kTypeWifi, "ssid", flimflam::kModeManaged, |
| 1064 | NULL, NULL, true, &e); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 1065 | EXPECT_EQ(1, GetServices().size()); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1066 | |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1067 | ReportBSS("bss", "ssid", "00:00:00:00:00:01", 0, 0, |
| 1068 | kNetworkModeInfrastructure); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1069 | ReportScanDone(); |
| 1070 | ReportCurrentBSSChanged("bss"); |
| 1071 | EXPECT_EQ(1, GetServices().size()); |
| 1072 | |
| 1073 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Disconnect()); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1074 | RemoveBSS("bss"); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1075 | EXPECT_EQ(1, GetServices().size()); |
| 1076 | // Verify expectations now, because WiFi may call UpdateService when |
| 1077 | // WiFi is Stop()-ed (during TearDown()). |
| 1078 | Mock::VerifyAndClearExpectations(manager()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1079 | EXPECT_CALL(*manager(), DeregisterService(_)).Times(AnyNumber()); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | TEST_F(WiFiMainTest, NonSolitaryBSSRemoved) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1083 | EXPECT_CALL(*manager(), RegisterService(_)); |
| 1084 | EXPECT_CALL(*manager(), HasService(_)); |
| 1085 | EXPECT_CALL(*manager(), UpdateService(_)); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 1086 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1087 | ReportBSS("bss0", "ssid", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 1088 | ReportBSS("bss1", "ssid", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 1089 | ReportScanDone(); |
| 1090 | EXPECT_EQ(1, GetServices().size()); |
| 1091 | EXPECT_TRUE(GetServices().front()->IsVisible()); |
| 1092 | |
| 1093 | EXPECT_CALL(*manager(), UpdateService(_)); |
| 1094 | RemoveBSS("bss0"); |
| 1095 | EXPECT_TRUE(GetServices().front()->IsVisible()); |
| 1096 | EXPECT_EQ(1, GetServices().size()); |
| 1097 | } |
| 1098 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 1099 | TEST_F(WiFiMainTest, Connect) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1100 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 1101 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1102 | *supplicant_interface_proxy_; |
| 1103 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 1104 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1105 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 1106 | ReportScanDone(); |
| 1107 | |
| 1108 | { |
| 1109 | InSequence s; |
| 1110 | DBus::Path fake_path("/fake/path"); |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 1111 | WiFiService *service(GetServices().begin()->get()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 1112 | |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 1113 | EXPECT_CALL(supplicant_interface_proxy, AddNetwork(_)) |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 1114 | .WillOnce(Return(fake_path)); |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 1115 | EXPECT_CALL(supplicant_interface_proxy, SelectNetwork(fake_path)); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1116 | InitiateConnect(service); |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 1117 | EXPECT_EQ(static_cast<Service *>(service), |
| 1118 | wifi()->selected_service_.get()); |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 1119 | EXPECT_EQ(Service::kStateAssociating, service->state()); |
| 1120 | EXPECT_FALSE(GetPendingTimeout().IsCancelled()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 1121 | } |
| 1122 | } |
| 1123 | |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1124 | TEST_F(WiFiMainTest, DisconnectPendingService) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1125 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1126 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1127 | *supplicant_interface_proxy_; |
| 1128 | |
| 1129 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1130 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1131 | WiFiService *service(GetServices().begin()->get()); |
| 1132 | InitiateConnect(service); |
| 1133 | |
| 1134 | EXPECT_FALSE(GetPendingService() == NULL); |
Paul Stewart | ff96a84 | 2012-08-13 15:59:10 -0700 | [diff] [blame] | 1135 | EXPECT_TRUE(service->IsConnecting()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1136 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()); |
| 1137 | InitiateDisconnect(service); |
Paul Stewart | ff96a84 | 2012-08-13 15:59:10 -0700 | [diff] [blame] | 1138 | EXPECT_FALSE(service->IsConnecting()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1139 | |
| 1140 | EXPECT_TRUE(GetPendingService() == NULL); |
| 1141 | } |
| 1142 | |
| 1143 | TEST_F(WiFiMainTest, DisconnectPendingServiceWithCurrent) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1144 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 1145 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _, _, _)).Times(AnyNumber()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1146 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(AnyNumber()); |
| 1147 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1148 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1149 | *supplicant_interface_proxy_; |
| 1150 | |
| 1151 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1152 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 1153 | ReportBSS("bss1", "ssid1", "00:00:00:00:00:01", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1154 | WiFiService *service0(GetServices()[0].get()); |
| 1155 | WiFiService *service1(GetServices()[1].get()); |
| 1156 | |
| 1157 | InitiateConnect(service0); |
| 1158 | ReportCurrentBSSChanged("bss0"); |
| 1159 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 1160 | InitiateConnect(service1); |
| 1161 | |
| 1162 | EXPECT_EQ(service0, GetCurrentService()); |
| 1163 | EXPECT_EQ(service1, GetPendingService()); |
| 1164 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()); |
| 1165 | InitiateDisconnect(service1); |
| 1166 | |
| 1167 | // |current_service_| will be unchanged until supplicant signals |
| 1168 | // that CurrentBSS has changed. |
| 1169 | EXPECT_EQ(service0, GetCurrentService()); |
| 1170 | // |pending_service_| is updated immediately. |
| 1171 | EXPECT_TRUE(GetPendingService() == NULL); |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 1172 | EXPECT_TRUE(GetPendingTimeout().IsCancelled()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | TEST_F(WiFiMainTest, DisconnectCurrentService) { |
| 1176 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1177 | *supplicant_interface_proxy_; |
Paul Stewart | 549d44c | 2012-07-03 12:40:25 -0700 | [diff] [blame] | 1178 | WiFiService *service(SetupConnectedService(DBus::Path())); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1179 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()); |
| 1180 | InitiateDisconnect(service); |
| 1181 | |
| 1182 | // |current_service_| should not change until supplicant reports |
| 1183 | // a BSS change. |
| 1184 | EXPECT_EQ(service, GetCurrentService()); |
| 1185 | } |
| 1186 | |
Christopher Wiley | c618448 | 2012-10-24 15:31:56 -0700 | [diff] [blame^] | 1187 | TEST_F(WiFiMainTest, DisconnectCurrentServiceWithErrors) { |
| 1188 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1189 | *supplicant_interface_proxy_; |
| 1190 | WiFiService *service(SetupConnectedService(DBus::Path())); |
| 1191 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()) |
| 1192 | .WillOnce(InvokeWithoutArgs(this, (&WiFiMainTest::ThrowDBusError))); |
| 1193 | InitiateDisconnect(service); |
| 1194 | |
| 1195 | // We may sometimes fail to disconnect via supplicant, and we patch up some |
| 1196 | // state when this happens. |
| 1197 | EXPECT_EQ(NULL, GetCurrentService().get()); |
| 1198 | EXPECT_EQ(NULL, wifi()->selected_service().get()); |
| 1199 | } |
| 1200 | |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1201 | TEST_F(WiFiMainTest, DisconnectCurrentServiceWithPending) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1202 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 1203 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _, _, _)).Times(AnyNumber()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1204 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(AnyNumber()); |
| 1205 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1206 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1207 | *supplicant_interface_proxy_; |
| 1208 | |
| 1209 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1210 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 1211 | ReportBSS("bss1", "ssid1", "00:00:00:00:00:01", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1212 | WiFiService *service0(GetServices()[0].get()); |
| 1213 | WiFiService *service1(GetServices()[1].get()); |
| 1214 | |
| 1215 | InitiateConnect(service0); |
| 1216 | ReportCurrentBSSChanged("bss0"); |
| 1217 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 1218 | InitiateConnect(service1); |
| 1219 | |
| 1220 | EXPECT_EQ(service0, GetCurrentService()); |
| 1221 | EXPECT_EQ(service1, GetPendingService()); |
| 1222 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()) |
| 1223 | .Times(0); |
| 1224 | InitiateDisconnect(service0); |
| 1225 | |
| 1226 | EXPECT_EQ(service0, GetCurrentService()); |
| 1227 | EXPECT_EQ(service1, GetPendingService()); |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 1228 | EXPECT_FALSE(GetPendingTimeout().IsCancelled()); |
| 1229 | } |
| 1230 | |
| 1231 | TEST_F(WiFiMainTest, TimeoutPendingService) { |
| 1232 | StartWiFi(); |
| 1233 | dispatcher_.DispatchPendingEvents(); |
| 1234 | const base::CancelableClosure &pending_timeout = GetPendingTimeout(); |
| 1235 | EXPECT_TRUE(pending_timeout.IsCancelled()); |
| 1236 | |
| 1237 | InSequence seq; |
| 1238 | MockWiFiServiceRefPtr service = MakeMockService(flimflam::kSecurityNone); |
| 1239 | EXPECT_CALL(*service, SetState(Service::kStateAssociating)); |
| 1240 | InitiateConnect(service); |
| 1241 | EXPECT_FALSE(pending_timeout.IsCancelled()); |
| 1242 | EXPECT_EQ(service, GetPendingService()); |
| 1243 | |
Paul Stewart | ff96a84 | 2012-08-13 15:59:10 -0700 | [diff] [blame] | 1244 | { |
| 1245 | InSequence seq; |
| 1246 | EXPECT_CALL(*service, SetState(Service::kStateIdle)); |
| 1247 | EXPECT_CALL(*service, SetFailure(Service::kFailureOutOfRange)); |
| 1248 | pending_timeout.callback().Run(); |
| 1249 | } |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 1250 | EXPECT_EQ(NULL, GetPendingService().get()); |
| 1251 | |
| 1252 | // Verify expectations now, because WiFi may report other state changes |
| 1253 | // when WiFi is Stop()-ed (during TearDown()). |
| 1254 | Mock::VerifyAndClearExpectations(service.get()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | TEST_F(WiFiMainTest, DisconnectInvalidService) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1258 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1259 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1260 | *supplicant_interface_proxy_; |
| 1261 | |
| 1262 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1263 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1264 | WiFiService *service(GetServices().begin()->get()); |
| 1265 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()) |
| 1266 | .Times(0); |
| 1267 | InitiateDisconnect(service); |
| 1268 | } |
| 1269 | |
| 1270 | TEST_F(WiFiMainTest, DisconnectCurrentServiceFailure) { |
| 1271 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1272 | *supplicant_interface_proxy_; |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1273 | DBus::Path fake_path("/fake/path"); |
Paul Stewart | 549d44c | 2012-07-03 12:40:25 -0700 | [diff] [blame] | 1274 | WiFiService *service(SetupConnectedService(fake_path)); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1275 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()) |
| 1276 | .WillRepeatedly(Throw( |
| 1277 | DBus::Error( |
| 1278 | "fi.w1.wpa_supplicant1.NotConnected", |
| 1279 | "test threw fi.w1.wpa_supplicant1.NotConnected"))); |
| 1280 | EXPECT_CALL(supplicant_interface_proxy, RemoveNetwork(fake_path)); |
| 1281 | InitiateDisconnect(service); |
| 1282 | |
| 1283 | EXPECT_TRUE(GetCurrentService() == NULL); |
| 1284 | } |
| 1285 | |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 1286 | TEST_F(WiFiMainTest, Stop) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1287 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 1288 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1289 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 1290 | ReportScanDone(); |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 1291 | |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 1292 | EXPECT_CALL(*manager(), DeregisterService(_)); |
| 1293 | StopWiFi(); |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 1294 | EXPECT_TRUE(GetScanTimer().IsCancelled()); |
mukesh agrawal | c4f368f | 2012-06-04 19:45:52 -0700 | [diff] [blame] | 1295 | EXPECT_FALSE(wifi()->weak_ptr_factory_.HasWeakPtrs()); |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 1296 | } |
| 1297 | |
Paul Stewart | 549d44c | 2012-07-03 12:40:25 -0700 | [diff] [blame] | 1298 | TEST_F(WiFiMainTest, StopWhileConnected) { |
| 1299 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1300 | *supplicant_interface_proxy_; |
| 1301 | WiFiService *service(SetupConnectedService(DBus::Path())); |
| 1302 | EXPECT_CALL(*manager(), DeregisterService(ServiceRefPtr(service))) |
| 1303 | .WillOnce(Invoke(this, &WiFiObjectTest::UnloadService)); |
| 1304 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()); |
| 1305 | StopWiFi(); |
| 1306 | EXPECT_TRUE(GetCurrentService() == NULL); |
| 1307 | } |
| 1308 | |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1309 | TEST_F(WiFiMainTest, ReconnectTimer) { |
| 1310 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1311 | *supplicant_interface_proxy_; |
| 1312 | WiFiService *service(SetupConnectedService(DBus::Path())); |
| 1313 | service->SetState(Service::kStateConnected); |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 1314 | EXPECT_TRUE(GetReconnectTimeoutCallback().IsCancelled()); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1315 | ReportStateChanged(wpa_supplicant::kInterfaceStateDisconnected); |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 1316 | EXPECT_FALSE(GetReconnectTimeoutCallback().IsCancelled()); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1317 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 1318 | EXPECT_TRUE(GetReconnectTimeoutCallback().IsCancelled()); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1319 | ReportStateChanged(wpa_supplicant::kInterfaceStateDisconnected); |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 1320 | EXPECT_FALSE(GetReconnectTimeoutCallback().IsCancelled()); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1321 | ReportCurrentBSSChanged(kBSSName); |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 1322 | EXPECT_TRUE(GetReconnectTimeoutCallback().IsCancelled()); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1323 | ReportStateChanged(wpa_supplicant::kInterfaceStateDisconnected); |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 1324 | EXPECT_FALSE(GetReconnectTimeoutCallback().IsCancelled()); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1325 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()); |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 1326 | GetReconnectTimeoutCallback().callback().Run(); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1327 | Mock::VerifyAndClearExpectations(&supplicant_interface_proxy_); |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 1328 | EXPECT_TRUE(GetReconnectTimeoutCallback().IsCancelled()); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1331 | TEST_F(WiFiMainTest, GetWifiServiceOpen) { |
| 1332 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1333 | GetOpenService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1334 | EXPECT_TRUE(e.IsSuccess()); |
| 1335 | } |
| 1336 | |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1337 | TEST_F(WiFiMainTest, GetWifiServiceOpenNoSSID) { |
| 1338 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1339 | GetOpenService(flimflam::kTypeWifi, NULL, flimflam::kModeManaged, &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1340 | EXPECT_EQ(Error::kInvalidArguments, e.type()); |
| 1341 | EXPECT_EQ("must specify SSID", e.message()); |
| 1342 | } |
| 1343 | |
| 1344 | TEST_F(WiFiMainTest, GetWifiServiceOpenLongSSID) { |
| 1345 | Error e; |
| 1346 | GetOpenService( |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1347 | flimflam::kTypeWifi, "123456789012345678901234567890123", |
| 1348 | flimflam::kModeManaged, &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1349 | EXPECT_EQ(Error::kInvalidNetworkName, e.type()); |
| 1350 | EXPECT_EQ("SSID is too long", e.message()); |
| 1351 | } |
| 1352 | |
| 1353 | TEST_F(WiFiMainTest, GetWifiServiceOpenShortSSID) { |
| 1354 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1355 | GetOpenService(flimflam::kTypeWifi, "", flimflam::kModeManaged, &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1356 | EXPECT_EQ(Error::kInvalidNetworkName, e.type()); |
| 1357 | EXPECT_EQ("SSID is too short", e.message()); |
| 1358 | } |
| 1359 | |
| 1360 | TEST_F(WiFiMainTest, GetWifiServiceOpenBadMode) { |
| 1361 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1362 | GetOpenService(flimflam::kTypeWifi, "an_ssid", "ad-hoc", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1363 | EXPECT_EQ(Error::kNotSupported, e.type()); |
| 1364 | EXPECT_EQ("service mode is unsupported", e.message()); |
| 1365 | } |
| 1366 | |
| 1367 | TEST_F(WiFiMainTest, GetWifiServiceOpenNoMode) { |
| 1368 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1369 | GetOpenService(flimflam::kTypeWifi, "an_ssid", NULL, &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1370 | EXPECT_TRUE(e.IsSuccess()); |
| 1371 | } |
| 1372 | |
| 1373 | TEST_F(WiFiMainTest, GetWifiServiceRSN) { |
| 1374 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1375 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1376 | flimflam::kSecurityRsn, "secure password", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1377 | EXPECT_TRUE(e.IsSuccess()); |
| 1378 | } |
| 1379 | |
| 1380 | TEST_F(WiFiMainTest, GetWifiServiceRSNNoPassword) { |
mukesh agrawal | b172e4a | 2012-04-25 18:15:30 -0700 | [diff] [blame] | 1381 | // When configuring hidden networks, Chrome expects to be able to |
| 1382 | // GetService w/o a password, and supply the password with |
| 1383 | // SetProperty afterwards. |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1384 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1385 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1386 | flimflam::kSecurityRsn, NULL, &e); |
mukesh agrawal | b172e4a | 2012-04-25 18:15:30 -0700 | [diff] [blame] | 1387 | EXPECT_TRUE(e.IsSuccess()); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | TEST_F(WiFiMainTest, GetWifiServiceBadSecurity) { |
| 1391 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1392 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, "rot-13", |
| 1393 | NULL, &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1394 | EXPECT_EQ(Error::kNotSupported, e.type()); |
| 1395 | EXPECT_EQ("security mode is unsupported", e.message()); |
| 1396 | } |
| 1397 | |
| 1398 | TEST_F(WiFiMainTest, GetWifiServiceWEPNoPassword) { |
mukesh agrawal | b172e4a | 2012-04-25 18:15:30 -0700 | [diff] [blame] | 1399 | // When configuring hidden networks, Chrome expects to be able to |
| 1400 | // GetService w/o a password, and supply the password with |
| 1401 | // SetProperty afterwards. |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1402 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1403 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1404 | flimflam::kSecurityWep, NULL, &e); |
mukesh agrawal | b172e4a | 2012-04-25 18:15:30 -0700 | [diff] [blame] | 1405 | EXPECT_TRUE(e.IsSuccess()); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | TEST_F(WiFiMainTest, GetWifiServiceWEPEmptyPassword) { |
| 1409 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1410 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1411 | flimflam::kSecurityWep, "", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1412 | EXPECT_EQ(Error::kInvalidPassphrase, e.type()); |
| 1413 | } |
| 1414 | |
| 1415 | TEST_F(WiFiMainTest, GetWifiServiceWEP40ASCII) { |
| 1416 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1417 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1418 | flimflam::kSecurityWep, "abcde", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1419 | EXPECT_TRUE(e.IsSuccess()); |
| 1420 | } |
| 1421 | |
| 1422 | TEST_F(WiFiMainTest, GetWifiServiceWEP104ASCII) { |
| 1423 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1424 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1425 | flimflam::kSecurityWep, "abcdefghijklm", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1426 | EXPECT_TRUE(e.IsSuccess()); |
| 1427 | } |
| 1428 | |
| 1429 | TEST_F(WiFiMainTest, GetWifiServiceWEP40ASCIIWithKeyIndex) { |
| 1430 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1431 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1432 | flimflam::kSecurityWep, "0:abcdefghijklm", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1433 | EXPECT_TRUE(e.IsSuccess()); |
| 1434 | } |
| 1435 | |
| 1436 | TEST_F(WiFiMainTest, GetWifiServiceWEP40Hex) { |
| 1437 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1438 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1439 | flimflam::kSecurityWep, "0102030405", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1440 | EXPECT_TRUE(e.IsSuccess()); |
| 1441 | } |
| 1442 | |
| 1443 | TEST_F(WiFiMainTest, GetWifiServiceWEP40HexBadPassphrase) { |
| 1444 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1445 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1446 | flimflam::kSecurityWep, "O102030405", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1447 | EXPECT_EQ(Error::kInvalidPassphrase, e.type()); |
| 1448 | } |
| 1449 | |
| 1450 | TEST_F(WiFiMainTest, GetWifiServiceWEP40HexWithKeyIndexBadPassphrase) { |
| 1451 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1452 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1453 | flimflam::kSecurityWep, "1:O102030405", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1454 | EXPECT_EQ(Error::kInvalidPassphrase, e.type()); |
| 1455 | } |
| 1456 | |
| 1457 | TEST_F(WiFiMainTest, GetWifiServiceWEP40HexWithKeyIndexAndBaseBadPassphrase) { |
| 1458 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1459 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1460 | flimflam::kSecurityWep, "1:0xO102030405", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1461 | EXPECT_EQ(Error::kInvalidPassphrase, e.type()); |
| 1462 | } |
| 1463 | |
| 1464 | TEST_F(WiFiMainTest, GetWifiServiceWEP40HexWithBaseBadPassphrase) { |
| 1465 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1466 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1467 | flimflam::kSecurityWep, "0xO102030405", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1468 | EXPECT_EQ(Error::kInvalidPassphrase, e.type()); |
| 1469 | } |
| 1470 | |
| 1471 | TEST_F(WiFiMainTest, GetWifiServiceWEP104Hex) { |
| 1472 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1473 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1474 | flimflam::kSecurityWep, "0102030405060708090a0b0c0d", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1475 | EXPECT_TRUE(e.IsSuccess()); |
| 1476 | } |
| 1477 | |
| 1478 | TEST_F(WiFiMainTest, GetWifiServiceWEP104HexUppercase) { |
| 1479 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1480 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1481 | flimflam::kSecurityWep, "0102030405060708090A0B0C0D", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1482 | EXPECT_TRUE(e.IsSuccess()); |
| 1483 | } |
| 1484 | |
| 1485 | TEST_F(WiFiMainTest, GetWifiServiceWEP104HexWithKeyIndex) { |
| 1486 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1487 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1488 | flimflam::kSecurityWep, "0:0102030405060708090a0b0c0d", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1489 | EXPECT_TRUE(e.IsSuccess()); |
| 1490 | } |
| 1491 | |
| 1492 | TEST_F(WiFiMainTest, GetWifiServiceWEP104HexWithKeyIndexAndBase) { |
| 1493 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1494 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1495 | flimflam::kSecurityWep, "0:0x0102030405060708090a0b0c0d", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1496 | EXPECT_TRUE(e.IsSuccess()); |
| 1497 | } |
| 1498 | |
mukesh agrawal | 8ede052 | 2011-10-03 14:57:44 -0700 | [diff] [blame] | 1499 | class WiFiGetServiceSuccessTest : public WiFiMainTest {}; |
| 1500 | class WiFiGetServiceFailureTest : public WiFiMainTest {}; |
| 1501 | |
| 1502 | TEST_P(WiFiGetServiceSuccessTest, Passphrase) { |
| 1503 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1504 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1505 | flimflam::kSecurityWpa, GetParam().c_str(), &e); |
mukesh agrawal | 8ede052 | 2011-10-03 14:57:44 -0700 | [diff] [blame] | 1506 | EXPECT_TRUE(e.IsSuccess()); |
| 1507 | } |
| 1508 | |
| 1509 | TEST_P(WiFiGetServiceFailureTest, Passphrase) { |
| 1510 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1511 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1512 | flimflam::kSecurityWpa, GetParam().c_str(), &e); |
mukesh agrawal | 8ede052 | 2011-10-03 14:57:44 -0700 | [diff] [blame] | 1513 | EXPECT_EQ(Error::kInvalidPassphrase, e.type()); |
| 1514 | } |
| 1515 | |
| 1516 | INSTANTIATE_TEST_CASE_P( |
| 1517 | WiFiGetServiceSuccessTestInstance, |
| 1518 | WiFiGetServiceSuccessTest, |
| 1519 | Values( |
| 1520 | string(IEEE_80211::kWPAAsciiMinLen, 'Z'), |
| 1521 | string(IEEE_80211::kWPAAsciiMaxLen, 'Z'), |
| 1522 | // subtle: invalid length for hex key, but valid as ascii passphrase |
| 1523 | string(IEEE_80211::kWPAHexLen-1, '1'), |
| 1524 | string(IEEE_80211::kWPAHexLen, '1'))); |
| 1525 | |
| 1526 | INSTANTIATE_TEST_CASE_P( |
| 1527 | WiFiGetServiceFailureTestInstance, |
| 1528 | WiFiGetServiceFailureTest, |
| 1529 | Values( |
| 1530 | string(IEEE_80211::kWPAAsciiMinLen-1, 'Z'), |
| 1531 | string(IEEE_80211::kWPAAsciiMaxLen+1, 'Z'), |
| 1532 | string(IEEE_80211::kWPAHexLen+1, '1'))); |
| 1533 | |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1534 | TEST_F(WiFiMainTest, FindServiceWEP) { |
| 1535 | const string ssid("an_ssid"); |
| 1536 | { |
| 1537 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1538 | GetService(flimflam::kTypeWifi, ssid.c_str(), flimflam::kModeManaged, |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1539 | flimflam::kSecurityWep, "abcde", &e); |
| 1540 | EXPECT_TRUE(e.IsSuccess()); |
| 1541 | } |
| 1542 | vector<uint8_t> ssid_bytes(ssid.begin(), ssid.end()); |
| 1543 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1544 | EXPECT_TRUE(FindService(ssid_bytes, flimflam::kModeManaged, |
| 1545 | flimflam::kSecurityWep).get()); |
| 1546 | EXPECT_FALSE(FindService(ssid_bytes, flimflam::kModeManaged, |
| 1547 | flimflam::kSecurityWpa).get()); |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | TEST_F(WiFiMainTest, FindServiceWPA) { |
| 1551 | const string ssid("an_ssid"); |
| 1552 | { |
| 1553 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1554 | GetService(flimflam::kTypeWifi, ssid.c_str(), flimflam::kModeManaged, |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1555 | flimflam::kSecurityRsn, "abcdefgh", &e); |
| 1556 | EXPECT_TRUE(e.IsSuccess()); |
| 1557 | } |
| 1558 | vector<uint8_t> ssid_bytes(ssid.begin(), ssid.end()); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1559 | WiFiServiceRefPtr wpa_service(FindService(ssid_bytes, flimflam::kModeManaged, |
| 1560 | flimflam::kSecurityWpa)); |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1561 | EXPECT_TRUE(wpa_service.get()); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1562 | WiFiServiceRefPtr rsn_service(FindService(ssid_bytes, flimflam::kModeManaged, |
| 1563 | flimflam::kSecurityRsn)); |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1564 | EXPECT_TRUE(rsn_service.get()); |
| 1565 | EXPECT_EQ(wpa_service.get(), rsn_service.get()); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1566 | WiFiServiceRefPtr psk_service(FindService(ssid_bytes, flimflam::kModeManaged, |
| 1567 | flimflam::kSecurityPsk)); |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1568 | EXPECT_EQ(wpa_service.get(), psk_service.get()); |
| 1569 | // Indirectly test FindService by doing a GetService on something that |
| 1570 | // already exists. |
| 1571 | { |
| 1572 | Error e; |
| 1573 | WiFiServiceRefPtr wpa_service2( |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1574 | GetServiceInner(flimflam::kTypeWifi, ssid.c_str(), |
| 1575 | flimflam::kModeManaged, flimflam::kSecurityWpa, |
| 1576 | "abcdefgh", false, &e)); |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1577 | EXPECT_TRUE(e.IsSuccess()); |
| 1578 | EXPECT_EQ(wpa_service.get(), wpa_service2.get()); |
| 1579 | } |
| 1580 | } |
| 1581 | |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1582 | TEST_F(WiFiMainTest, GetServiceWithGUID) { |
| 1583 | // Perform a GetService that also configures properties in the base Service |
| 1584 | // class using Service::Configure(). |
| 1585 | KeyValueStore args; |
| 1586 | args.SetString(flimflam::kTypeProperty, flimflam::kTypeWifi); |
| 1587 | args.SetString(flimflam::kSSIDProperty, "ssid"); |
| 1588 | args.SetString(flimflam::kSecurityProperty, flimflam::kSecurityNone); |
| 1589 | const string kGUID = "aguid"; // Stored as a registered Service property. |
| 1590 | args.SetString(flimflam::kGuidProperty, kGUID); |
| 1591 | Error e; |
| 1592 | WiFiServiceRefPtr service = GetServiceWithKeyValues(args, &e); |
| 1593 | EXPECT_TRUE(e.IsSuccess()); |
| 1594 | EXPECT_EQ(kGUID, service->guid()); |
| 1595 | } |
| 1596 | |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 1597 | MATCHER_P(HasHiddenSSID, ssid, "") { |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1598 | map<string, DBus::Variant>::const_iterator it = |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 1599 | arg.find(wpa_supplicant::kPropertyScanSSIDs); |
| 1600 | if (it == arg.end()) { |
| 1601 | return false; |
| 1602 | } |
| 1603 | |
| 1604 | const DBus::Variant &ssids_variant = it->second; |
| 1605 | EXPECT_TRUE(DBusAdaptor::IsByteArrays(ssids_variant.signature())); |
| 1606 | const ByteArrays &ssids = it->second.operator ByteArrays(); |
| 1607 | // A valid Scan containing a single hidden SSID should contain |
| 1608 | // two SSID entries: one containing the SSID we are looking for, |
| 1609 | // and an empty entry, signifying that we also want to do a |
| 1610 | // broadcast probe request for all non-hidden APs as well. |
| 1611 | return ssids.size() == 2 && |
| 1612 | string(ssids[0].begin(), ssids[0].end()) == ssid && |
| 1613 | ssids[1].empty(); |
| 1614 | } |
| 1615 | |
| 1616 | TEST_F(WiFiMainTest, ScanHidden) { |
| 1617 | EXPECT_CALL(*supplicant_process_proxy_, CreateInterface(_)); |
| 1618 | EXPECT_CALL(*supplicant_process_proxy_, GetInterface(_)) |
| 1619 | .Times(AnyNumber()) |
| 1620 | .WillRepeatedly(Throw( |
| 1621 | DBus::Error( |
| 1622 | "fi.w1.wpa_supplicant1.InterfaceUnknown", |
| 1623 | "test threw fi.w1.wpa_supplicant1.InterfaceUnknown"))); |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1624 | scoped_refptr<MockProfile> profile( |
| 1625 | new NiceMock<MockProfile>(control_interface(), manager(), "")); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1626 | { |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1627 | // Create a hidden service with an associated profile. |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1628 | Error e; |
| 1629 | WiFiServiceRefPtr service = |
| 1630 | GetServiceInner(flimflam::kTypeWifi, "ssid0", flimflam::kModeManaged, |
| 1631 | NULL, NULL, true, &e); |
| 1632 | EXPECT_TRUE(e.IsSuccess()); |
| 1633 | EXPECT_TRUE(service->hidden_ssid()); |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1634 | service->set_profile(profile); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1635 | } |
| 1636 | { |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1637 | // Create a hidden service without an associated profile. |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1638 | Error e; |
| 1639 | WiFiServiceRefPtr service = |
| 1640 | GetServiceInner(flimflam::kTypeWifi, "ssid1", flimflam::kModeManaged, |
| 1641 | NULL, NULL, true, &e); |
| 1642 | EXPECT_TRUE(e.IsSuccess()); |
| 1643 | EXPECT_TRUE(service->hidden_ssid()); |
| 1644 | } |
| 1645 | { |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1646 | // Create a non-hidden service with an associated profile. |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1647 | Error e; |
| 1648 | WiFiServiceRefPtr service = |
| 1649 | GetServiceInner(flimflam::kTypeWifi, "ssid2", flimflam::kModeManaged, |
| 1650 | NULL, NULL, false, &e); |
| 1651 | EXPECT_TRUE(e.IsSuccess()); |
| 1652 | EXPECT_FALSE(service->hidden_ssid()); |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1653 | service->set_profile(profile); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1654 | } |
| 1655 | EXPECT_CALL(*supplicant_interface_proxy_, Scan(HasHiddenSSID("ssid0"))); |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 1656 | StartWiFi(); |
| 1657 | dispatcher_.DispatchPendingEvents(); |
| 1658 | } |
| 1659 | |
Paul Stewart | fae4dae | 2012-09-13 07:43:32 -0700 | [diff] [blame] | 1660 | TEST_F(WiFiMainTest, ScanWiFiDisabledAfterResume) { |
| 1661 | ScopedMockLog log; |
| 1662 | EXPECT_CALL(log, Log(_, _, _)).Times(AnyNumber()); |
| 1663 | EXPECT_CALL(log, Log(_, _, EndsWith( |
| 1664 | "Ignoring scan request while device is not enabled."))).Times(1); |
| 1665 | EXPECT_CALL(*supplicant_interface_proxy_, Scan(_)).Times(0); |
| 1666 | StartWiFi(); |
| 1667 | StopWiFi(); |
| 1668 | // A scan is queued when WiFi resumes. |
| 1669 | OnAfterResume(); |
| 1670 | dispatcher_.DispatchPendingEvents(); |
| 1671 | } |
| 1672 | |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1673 | TEST_F(WiFiMainTest, InitialSupplicantState) { |
| 1674 | EXPECT_EQ(WiFi::kInterfaceStateUnknown, GetSupplicantState()); |
| 1675 | } |
| 1676 | |
| 1677 | TEST_F(WiFiMainTest, StateChangeNoService) { |
| 1678 | // State change should succeed even if there is no pending Service. |
| 1679 | ReportStateChanged(wpa_supplicant::kInterfaceStateScanning); |
| 1680 | EXPECT_EQ(wpa_supplicant::kInterfaceStateScanning, GetSupplicantState()); |
| 1681 | } |
| 1682 | |
| 1683 | TEST_F(WiFiMainTest, StateChangeWithService) { |
| 1684 | // Forward transition should trigger a Service state change. |
| 1685 | StartWiFi(); |
| 1686 | dispatcher_.DispatchPendingEvents(); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 1687 | MockWiFiServiceRefPtr service = MakeMockService(flimflam::kSecurityNone); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1688 | InitiateConnect(service); |
| 1689 | EXPECT_CALL(*service.get(), SetState(Service::kStateAssociating)); |
| 1690 | ReportStateChanged(wpa_supplicant::kInterfaceStateAssociated); |
| 1691 | // Verify expectations now, because WiFi may report other state changes |
| 1692 | // when WiFi is Stop()-ed (during TearDown()). |
| 1693 | Mock::VerifyAndClearExpectations(service.get()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1694 | EXPECT_CALL(*service.get(), SetState(_)).Times(AnyNumber()); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | TEST_F(WiFiMainTest, StateChangeBackwardsWithService) { |
| 1698 | // Some backwards transitions should not trigger a Service state change. |
| 1699 | // Supplicant state should still be updated, however. |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 1700 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _, _, _)).Times(AnyNumber()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1701 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(AnyNumber()); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1702 | StartWiFi(); |
| 1703 | dispatcher_.DispatchPendingEvents(); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 1704 | MockWiFiServiceRefPtr service = MakeMockService(flimflam::kSecurityNone); |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 1705 | EXPECT_CALL(*service.get(), SetState(Service::kStateAssociating)); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1706 | EXPECT_CALL(*service.get(), SetState(Service::kStateConfiguring)); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1707 | InitiateConnect(service); |
| 1708 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1709 | ReportStateChanged(wpa_supplicant::kInterfaceStateAuthenticating); |
| 1710 | EXPECT_EQ(wpa_supplicant::kInterfaceStateAuthenticating, |
| 1711 | GetSupplicantState()); |
| 1712 | // Verify expectations now, because WiFi may report other state changes |
| 1713 | // when WiFi is Stop()-ed (during TearDown()). |
| 1714 | Mock::VerifyAndClearExpectations(service.get()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1715 | EXPECT_CALL(*service.get(), SetState(_)).Times(AnyNumber()); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1716 | } |
| 1717 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1718 | TEST_F(WiFiMainTest, LoadHiddenServicesFailWithNoGroups) { |
| 1719 | StrictMock<MockStore> storage; |
| 1720 | EXPECT_CALL(storage, GetGroupsWithKey(flimflam::kWifiHiddenSsid)) |
| 1721 | .WillOnce(Return(set<string>())); |
| 1722 | EXPECT_FALSE(LoadHiddenServices(&storage)); |
| 1723 | } |
| 1724 | |
| 1725 | TEST_F(WiFiMainTest, LoadHiddenServicesFailWithMissingHidden) { |
| 1726 | string id; |
| 1727 | StrictMock<MockStore> storage; |
| 1728 | SetupHiddenStorage(&storage, "an_ssid", &id); |
| 1729 | // Missing "Hidden" property. |
| 1730 | EXPECT_CALL(storage, GetBool(StrEq(id), flimflam::kWifiHiddenSsid, _)) |
| 1731 | .WillOnce(Return(false)); |
| 1732 | EXPECT_FALSE(LoadHiddenServices(&storage)); |
| 1733 | } |
| 1734 | |
| 1735 | TEST_F(WiFiMainTest, LoadHiddenServicesFailWithFalseHidden) { |
| 1736 | string id; |
| 1737 | StrictMock<MockStore> storage; |
| 1738 | SetupHiddenStorage(&storage, "an_ssid", &id); |
| 1739 | // "Hidden" property set to "false". |
| 1740 | EXPECT_CALL(storage, GetBool(StrEq(id), flimflam::kWifiHiddenSsid, _)) |
| 1741 | .WillOnce(DoAll(SetArgumentPointee<2>(true), Return(false))); |
| 1742 | EXPECT_FALSE(LoadHiddenServices(&storage)); |
| 1743 | } |
| 1744 | |
| 1745 | TEST_F(WiFiMainTest, LoadHiddenServicesFailWithMissingSSID) { |
| 1746 | string id; |
| 1747 | StrictMock<MockStore> storage; |
| 1748 | SetupHiddenStorage(&storage, "an_ssid", &id); |
| 1749 | // Missing "SSID" property. |
| 1750 | EXPECT_CALL(storage, GetString(StrEq(id), flimflam::kSSIDProperty, _)) |
| 1751 | .WillOnce(Return(false)); |
| 1752 | EXPECT_FALSE(LoadHiddenServices(&storage)); |
| 1753 | } |
| 1754 | |
| 1755 | |
| 1756 | TEST_F(WiFiMainTest, LoadHiddenServicesFailWithFoundService) { |
| 1757 | StrictMock<MockStore> storage; |
| 1758 | string id; |
| 1759 | SetupHiddenStorage(&storage, "an_ssid", &id); |
| 1760 | Error e; |
| 1761 | GetOpenService(flimflam::kTypeWifi, "an_ssid", NULL, &e); |
| 1762 | ASSERT_TRUE(e.IsSuccess()); |
| 1763 | EXPECT_FALSE(LoadHiddenServices(&storage)); |
| 1764 | } |
| 1765 | |
| 1766 | TEST_F(WiFiMainTest, LoadHiddenServicesSuccess) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1767 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1768 | StrictMock<MockStore> storage; |
| 1769 | string ssid("an_ssid"); |
| 1770 | string id; |
| 1771 | SetupHiddenStorage(&storage, ssid, &id); |
| 1772 | EXPECT_TRUE(LoadHiddenServices(&storage)); |
| 1773 | vector<uint8_t> ssid_bytes(ssid.begin(), ssid.end()); |
| 1774 | EXPECT_TRUE(FindService(ssid_bytes, flimflam::kModeManaged, |
| 1775 | flimflam::kSecurityNone).get()); |
| 1776 | } |
| 1777 | |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1778 | TEST_F(WiFiMainTest, CurrentBSSChangeConnectedToDisconnected) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1779 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 1780 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _, _, _)).Times(AnyNumber()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1781 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(AnyNumber()); |
| 1782 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1783 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 1784 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 1785 | |
| 1786 | // Note that the BSS handle used in this test ("an_ap") is not |
| 1787 | // intended to reflect the format used by supplicant. It's just |
| 1788 | // convenient for testing. |
| 1789 | |
| 1790 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1791 | ReportBSS("an_ap", ap->ssid_string(), ap->bssid_string(), 0, 0, |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1792 | kNetworkModeInfrastructure); |
| 1793 | InitiateConnect(service); |
| 1794 | EXPECT_EQ(service, GetPendingService().get()); |
| 1795 | |
| 1796 | ReportCurrentBSSChanged("an_ap"); |
| 1797 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 1798 | EXPECT_EQ(Service::kStateConfiguring, service->state()); |
| 1799 | EXPECT_EQ(service, GetCurrentService().get()); |
| 1800 | EXPECT_EQ(NULL, GetPendingService().get()); |
| 1801 | |
| 1802 | ReportCurrentBSSChanged(wpa_supplicant::kCurrentBSSNull); |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 1803 | EXPECT_EQ(Service::kStateIdle, service->state()); |
| 1804 | EXPECT_TRUE(service->IsFailed()); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1805 | EXPECT_EQ(NULL, GetCurrentService().get()); |
| 1806 | EXPECT_EQ(NULL, GetPendingService().get()); |
| 1807 | } |
| 1808 | |
| 1809 | TEST_F(WiFiMainTest, CurrentBSSChangeConnectedToConnectedNewService) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1810 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 1811 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _, _, _)).Times(AnyNumber()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1812 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(AnyNumber()); |
| 1813 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1814 | WiFiEndpointRefPtr ap1 = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 1815 | WiFiEndpointRefPtr ap2 = MakeEndpoint("another_ssid", "01:02:03:04:05:06"); |
| 1816 | WiFiServiceRefPtr service1 = CreateServiceForEndpoint(*ap1); |
| 1817 | WiFiServiceRefPtr service2 = CreateServiceForEndpoint(*ap2); |
| 1818 | |
| 1819 | // Note that the BSS handles used in this test ("ap1", "ap2") are |
| 1820 | // not intended to reflect the format used by supplicant. They're |
| 1821 | // just convenient for testing. |
| 1822 | |
| 1823 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1824 | ReportBSS("ap1", ap1->ssid_string(), ap1->bssid_string(), 0, 0, |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1825 | kNetworkModeInfrastructure); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1826 | ReportBSS("ap2", ap2->ssid_string(), ap2->bssid_string(), 0, 0, |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1827 | kNetworkModeInfrastructure); |
| 1828 | InitiateConnect(service1); |
| 1829 | ReportCurrentBSSChanged("ap1"); |
| 1830 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 1831 | EXPECT_EQ(service1.get(), GetCurrentService().get()); |
| 1832 | |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 1833 | // Note that we deliberately omit intermediate supplicant states |
| 1834 | // (e.g. kInterfaceStateAssociating), on the theory that they are |
| 1835 | // unreliable. Specifically, they may be quashed if the association |
| 1836 | // completes before supplicant flushes its changed properties. |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1837 | ReportCurrentBSSChanged("ap2"); |
| 1838 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 1839 | EXPECT_EQ(service2.get(), GetCurrentService().get()); |
| 1840 | EXPECT_EQ(Service::kStateIdle, service1->state()); |
| 1841 | EXPECT_EQ(Service::kStateConfiguring, service2->state()); |
| 1842 | } |
| 1843 | |
| 1844 | TEST_F(WiFiMainTest, CurrentBSSChangeDisconnectedToConnected) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1845 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
| 1846 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 1847 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _, _, _)).Times(AnyNumber()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1848 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(AnyNumber()); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1849 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 1850 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 1851 | |
| 1852 | // Note that the BSS handle used in this test ("an_ap") is not |
| 1853 | // intended to reflect the format used by supplicant. It's just |
| 1854 | // convenient for testing. |
| 1855 | |
| 1856 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1857 | ReportBSS("an_ap", ap->ssid_string(), ap->bssid_string(), 0, 0, |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1858 | kNetworkModeInfrastructure); |
| 1859 | InitiateConnect(service); |
| 1860 | ReportCurrentBSSChanged("an_ap"); |
| 1861 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 1862 | EXPECT_EQ(service.get(), GetCurrentService().get()); |
| 1863 | EXPECT_EQ(Service::kStateConfiguring, service->state()); |
| 1864 | } |
| 1865 | |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1866 | TEST_F(WiFiMainTest, CurrentBSSChangedUpdateServiceEndpoint) { |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 1867 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
| 1868 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
| 1869 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
| 1870 | |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1871 | const uint16 frequency1 = 2412; |
| 1872 | const uint16 frequency2 = 2442; |
| 1873 | StartWiFi(); |
| 1874 | ReportBSS("bss1", "ssid1", "00:00:00:00:00:01", 1, frequency1, |
| 1875 | kNetworkModeInfrastructure); |
| 1876 | ReportBSS("bss2", "ssid1", "00:00:00:00:00:02", 1, frequency2, |
| 1877 | kNetworkModeInfrastructure); |
| 1878 | EXPECT_EQ(1, GetServices().size()); |
| 1879 | WiFiService *service(GetServices()[0].get()); |
| 1880 | InitiateConnect(service); |
| 1881 | ReportCurrentBSSChanged("bss1"); |
| 1882 | EXPECT_EQ(frequency1, service->frequency_); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 1883 | EXPECT_EQ("00:00:00:00:00:01", service->bssid_); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1884 | ReportCurrentBSSChanged("bss2"); |
| 1885 | EXPECT_EQ(frequency2, service->frequency_); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 1886 | EXPECT_EQ("00:00:00:00:00:02", service->bssid_); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1887 | } |
| 1888 | |
mukesh agrawal | 4eb4d78 | 2011-12-05 17:34:37 +0000 | [diff] [blame] | 1889 | TEST_F(WiFiMainTest, ConfiguredServiceRegistration) { |
| 1890 | Error e; |
| 1891 | EXPECT_CALL(*manager(), RegisterService(_)) |
| 1892 | .Times(0); |
| 1893 | EXPECT_CALL(*manager(), HasService(_)) |
| 1894 | .WillOnce(Return(false)); |
| 1895 | GetOpenService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, &e); |
| 1896 | EXPECT_CALL(*manager(), RegisterService(_)); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1897 | ReportBSS("ap0", "an_ssid", "00:00:00:00:00:00", 0, 0, |
mukesh agrawal | 4eb4d78 | 2011-12-05 17:34:37 +0000 | [diff] [blame] | 1898 | kNetworkModeInfrastructure); |
| 1899 | } |
| 1900 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1901 | TEST_F(WiFiMainTest, NewConnectPreemptsPending) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1902 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
| 1903 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1904 | WiFiEndpointRefPtr ap1 = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 1905 | WiFiEndpointRefPtr ap2 = MakeEndpoint("another_ssid", "01:02:03:04:05:06"); |
| 1906 | WiFiServiceRefPtr service1 = CreateServiceForEndpoint(*ap1); |
| 1907 | WiFiServiceRefPtr service2 = CreateServiceForEndpoint(*ap2); |
| 1908 | |
| 1909 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1910 | ReportBSS("ap1", ap1->ssid_string(), ap1->bssid_string(), 0, 0, |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1911 | kNetworkModeInfrastructure); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1912 | ReportBSS("ap2", ap2->ssid_string(), ap2->bssid_string(), 0, 0, |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1913 | kNetworkModeInfrastructure); |
| 1914 | InitiateConnect(service1); |
| 1915 | EXPECT_EQ(service1.get(), GetPendingService().get()); |
| 1916 | |
| 1917 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Disconnect()); |
| 1918 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), AddNetwork(_)); |
| 1919 | InitiateConnect(service2); |
| 1920 | EXPECT_EQ(service2.get(), GetPendingService().get()); |
| 1921 | } |
| 1922 | |
| 1923 | TEST_F(WiFiMainTest, IsIdle) { |
| 1924 | StartWiFi(); |
| 1925 | EXPECT_TRUE(wifi()->IsIdle()); |
| 1926 | |
| 1927 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 1928 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 1929 | Error error; |
| 1930 | service->AddEndpoint(ap); |
| 1931 | service->AutoConnect(); |
| 1932 | EXPECT_FALSE(wifi()->IsIdle()); |
| 1933 | } |
| 1934 | |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 1935 | MATCHER_P(WiFiAddedArgs, bgscan, "") { |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 1936 | return ContainsKey(arg, wpa_supplicant::kNetworkPropertyScanSSID) && |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 1937 | ContainsKey(arg, wpa_supplicant::kNetworkPropertyBgscan) == bgscan; |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 1938 | } |
| 1939 | |
| 1940 | TEST_F(WiFiMainTest, AddNetworkArgs) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1941 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 1942 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1943 | *supplicant_interface_proxy_; |
| 1944 | |
| 1945 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1946 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 1947 | WiFiService *service(GetServices().begin()->get()); |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 1948 | EXPECT_CALL(supplicant_interface_proxy, AddNetwork(WiFiAddedArgs(true))); |
| 1949 | EXPECT_TRUE(SetBgscanMethod(wpa_supplicant::kNetworkBgscanMethodSimple)); |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 1950 | InitiateConnect(service); |
| 1951 | } |
| 1952 | |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 1953 | TEST_F(WiFiMainTest, AddNetworkArgsNoBgscan) { |
| 1954 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
| 1955 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1956 | *supplicant_interface_proxy_; |
| 1957 | |
| 1958 | StartWiFi(); |
| 1959 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 1960 | WiFiService *service(GetServices().begin()->get()); |
| 1961 | EXPECT_CALL(supplicant_interface_proxy, AddNetwork(WiFiAddedArgs(false))); |
| 1962 | InitiateConnect(service); |
| 1963 | } |
| 1964 | |
| 1965 | TEST_F(WiFiMainTest, AppendBgscan) { |
| 1966 | StartWiFi(); |
| 1967 | WiFiEndpointRefPtr ap1 = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 1968 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap1); |
| 1969 | service->AddEndpoint(ap1); |
| 1970 | EXPECT_EQ(1, service->GetEndpointCount()); |
| 1971 | { |
| 1972 | // 1 endpoint, default bgscan method -- background scan disabled. |
| 1973 | std::map<std::string, DBus::Variant> params; |
| 1974 | AppendBgscan(service.get(), ¶ms); |
| 1975 | EXPECT_FALSE(ContainsKey(params, wpa_supplicant::kNetworkPropertyBgscan)); |
| 1976 | } |
| 1977 | WiFiEndpointRefPtr ap2 = MakeEndpoint("an_ssid", "01:02:03:04:05:06"); |
| 1978 | service->AddEndpoint(ap2); |
| 1979 | EXPECT_EQ(2, service->GetEndpointCount()); |
| 1980 | { |
| 1981 | // 2 endpoints, default bgscan method -- background scan frequency reduced. |
| 1982 | map<string, DBus::Variant> params; |
| 1983 | AppendBgscan(service.get(), ¶ms); |
| 1984 | string config_string; |
| 1985 | EXPECT_TRUE( |
| 1986 | DBusProperties::GetString(params, |
| 1987 | wpa_supplicant::kNetworkPropertyBgscan, |
| 1988 | &config_string)); |
| 1989 | vector<string> elements; |
| 1990 | base::SplitString(config_string, ':', &elements); |
| 1991 | ASSERT_EQ(4, elements.size()); |
| 1992 | EXPECT_EQ(WiFi::kDefaultBgscanMethod, elements[0]); |
| 1993 | EXPECT_EQ(StringPrintf("%d", WiFi::kBackgroundScanIntervalSeconds), |
| 1994 | elements[3]); |
| 1995 | } |
| 1996 | { |
| 1997 | // Explicit bgscan method -- regular background scan frequency. |
| 1998 | EXPECT_TRUE(SetBgscanMethod(wpa_supplicant::kNetworkBgscanMethodSimple)); |
| 1999 | std::map<std::string, DBus::Variant> params; |
| 2000 | AppendBgscan(service.get(), ¶ms); |
| 2001 | string config_string; |
| 2002 | EXPECT_TRUE( |
| 2003 | DBusProperties::GetString(params, |
| 2004 | wpa_supplicant::kNetworkPropertyBgscan, |
| 2005 | &config_string)); |
| 2006 | vector<string> elements; |
| 2007 | base::SplitString(config_string, ':', &elements); |
| 2008 | ASSERT_EQ(4, elements.size()); |
| 2009 | EXPECT_EQ(StringPrintf("%d", WiFi::kDefaultScanIntervalSeconds), |
| 2010 | elements[3]); |
| 2011 | } |
Christopher Wiley | 5c929e2 | 2012-07-16 14:06:04 -0700 | [diff] [blame] | 2012 | { |
| 2013 | // No scan method, simply returns without appending properties |
| 2014 | EXPECT_TRUE(SetBgscanMethod(wpa_supplicant::kNetworkBgscanMethodNone)); |
| 2015 | std::map<std::string, DBus::Variant> params; |
| 2016 | AppendBgscan(service.get(), ¶ms); |
| 2017 | string config_string; |
| 2018 | EXPECT_FALSE( |
| 2019 | DBusProperties::GetString(params, |
| 2020 | wpa_supplicant::kNetworkPropertyBgscan, |
| 2021 | &config_string)); |
| 2022 | } |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 2023 | } |
| 2024 | |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 2025 | TEST_F(WiFiMainTest, StateAndIPIgnoreLinkEvent) { |
| 2026 | StartWiFi(); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 2027 | MockWiFiServiceRefPtr service = MakeMockService(flimflam::kSecurityNone); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 2028 | InitiateConnect(service); |
| 2029 | EXPECT_CALL(*service.get(), SetState(_)).Times(0); |
| 2030 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(0); |
| 2031 | ReportLinkUp(); |
| 2032 | |
| 2033 | // Verify expectations now, because WiFi may cause |service| state |
| 2034 | // changes during TearDown(). |
| 2035 | Mock::VerifyAndClearExpectations(service); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 2036 | EXPECT_CALL(*service.get(), SetState(_)).Times(AnyNumber()); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 2037 | } |
| 2038 | |
| 2039 | TEST_F(WiFiMainTest, SupplicantCompleted) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 2040 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 2041 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _, _, _)).Times(AnyNumber()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 2042 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 2043 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 2044 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 2045 | |
| 2046 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 2047 | ReportBSS("ap", ap->ssid_string(), ap->bssid_string(), 0, 0, |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 2048 | kNetworkModeInfrastructure); |
| 2049 | InitiateConnect(service); |
| 2050 | |
| 2051 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()); |
| 2052 | ReportCurrentBSSChanged("ap"); |
| 2053 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 2054 | EXPECT_EQ(Service::kStateConfiguring, service->state()); |
| 2055 | } |
| 2056 | |
| 2057 | TEST_F(WiFiMainTest, SupplicantCompletedAlreadyConnected) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 2058 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()); |
| 2059 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
| 2060 | EXPECT_CALL(*device_info(), FlushAddresses(_)).Times(AnyNumber()); |
| 2061 | EXPECT_CALL(*manager(), device_info()).Times(AnyNumber()); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 2062 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _, _, _)).Times(AnyNumber()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 2063 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 2064 | EXPECT_CALL(*manager(), IsPortalDetectionEnabled(_)).Times(AnyNumber()); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 2065 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 2066 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 2067 | |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 2068 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 2069 | ReportBSS("ap", ap->ssid_string(), ap->bssid_string(), 0, 0, |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 2070 | kNetworkModeInfrastructure); |
| 2071 | InitiateConnect(service); |
| 2072 | ReportCurrentBSSChanged("ap"); |
| 2073 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
Christopher Wiley | 8f81e2a | 2012-10-17 16:51:32 -0700 | [diff] [blame] | 2074 | Mock::VerifyAndClearExpectations(dhcp_config_.get()); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 2075 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(0); |
Christopher Wiley | 8f81e2a | 2012-10-17 16:51:32 -0700 | [diff] [blame] | 2076 | // Simulate a rekeying event from the AP. These show as transitions from |
| 2077 | // completed->completed from wpa_supplicant. |
| 2078 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 2079 | ReportIPConfigComplete(); |
| 2080 | // Similarly, rekeying events after we have an IP don't trigger L3 |
| 2081 | // configuration. |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 2082 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 2083 | } |
| 2084 | |
Paul Stewart | 66c8600 | 2012-01-30 18:00:52 -0800 | [diff] [blame] | 2085 | TEST_F(WiFiMainTest, ClearCachedCredentials) { |
Paul Stewart | f48eca4 | 2012-10-11 12:10:02 -0700 | [diff] [blame] | 2086 | { |
| 2087 | ClearCachedCredentials(); |
| 2088 | ScopedMockLog log; |
| 2089 | EXPECT_CALL(log, Log(_, _, EndsWith("supplicant proxy is NULL."))); |
| 2090 | // Also expect no crash due to supplicant interface proxy being NULL. |
| 2091 | dispatcher_.DispatchPendingEvents(); |
| 2092 | } |
| 2093 | |
Paul Stewart | 66c8600 | 2012-01-30 18:00:52 -0800 | [diff] [blame] | 2094 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 2095 | *supplicant_interface_proxy_; |
| 2096 | |
| 2097 | StartWiFi(); |
| 2098 | |
| 2099 | // Ensure call to the proxy is deferred. |
| 2100 | EXPECT_CALL(supplicant_interface_proxy, ClearCachedCredentials()) |
| 2101 | .Times(0); |
| 2102 | ClearCachedCredentials(); |
| 2103 | |
| 2104 | Mock::VerifyAndClearExpectations(&supplicant_interface_proxy); |
| 2105 | |
| 2106 | EXPECT_CALL(supplicant_interface_proxy, ClearCachedCredentials()) |
| 2107 | .Times(1); |
| 2108 | dispatcher_.DispatchPendingEvents(); |
| 2109 | |
| 2110 | Mock::VerifyAndClearExpectations(&supplicant_interface_proxy); |
| 2111 | |
| 2112 | EXPECT_CALL(supplicant_interface_proxy, ClearCachedCredentials()) |
| 2113 | .Times(0); |
| 2114 | ClearCachedCredentials(); |
| 2115 | ClearCachedCredentials(); |
| 2116 | |
| 2117 | Mock::VerifyAndClearExpectations(&supplicant_interface_proxy); |
| 2118 | |
| 2119 | // Ensure multiple calls to ClearCachedCredentials() results in only |
| 2120 | // one call to the proxy. |
| 2121 | EXPECT_CALL(supplicant_interface_proxy, ClearCachedCredentials()) |
| 2122 | .Times(1); |
| 2123 | dispatcher_.DispatchPendingEvents(); |
| 2124 | } |
| 2125 | |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 2126 | TEST_F(WiFiMainTest, BSSAddedCreatesBSSProxy) { |
| 2127 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
| 2128 | // TODO(quiche): Consider using a factory for WiFiEndpoints, so that |
| 2129 | // we can test the interaction between WiFi and WiFiEndpoint. (Right |
| 2130 | // now, we're testing across multiple layers.) |
| 2131 | EXPECT_CALL(*supplicant_bss_proxy_, Die()).Times(AnyNumber()); |
| 2132 | EXPECT_CALL(*proxy_factory(), CreateSupplicantBSSProxy(_, _, _)); |
| 2133 | StartWiFi(); |
| 2134 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 2135 | } |
| 2136 | |
| 2137 | TEST_F(WiFiMainTest, BSSRemovedDestroysBSSProxy) { |
| 2138 | // TODO(quiche): As for BSSAddedCreatesBSSProxy, consider using a |
| 2139 | // factory for WiFiEndpoints. |
| 2140 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
| 2141 | |
| 2142 | // Get the pointer before we transfer ownership. |
| 2143 | MockSupplicantBSSProxy *proxy = supplicant_bss_proxy_.get(); |
| 2144 | EXPECT_CALL(*proxy, Die()); |
| 2145 | StartWiFi(); |
| 2146 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 2147 | RemoveBSS("bss0"); |
| 2148 | // Check this now, to make sure RemoveBSS killed the proxy (rather |
| 2149 | // than TearDown). |
| 2150 | Mock::VerifyAndClearExpectations(proxy); |
| 2151 | } |
| 2152 | |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 2153 | TEST_F(WiFiMainTest, FlushBSSOnResume) { |
| 2154 | const struct timeval resume_time = {1, 0}; |
| 2155 | const struct timeval scan_done_time = {6, 0}; |
| 2156 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 2157 | *supplicant_interface_proxy_; |
| 2158 | |
| 2159 | StartWiFi(); |
| 2160 | |
| 2161 | EXPECT_CALL(time_, GetTimeMonotonic(_)) |
| 2162 | .WillOnce(DoAll(SetArgumentPointee<0>(resume_time), Return(0))) |
| 2163 | .WillOnce(DoAll(SetArgumentPointee<0>(scan_done_time), Return(0))); |
| 2164 | EXPECT_CALL(supplicant_interface_proxy, |
| 2165 | FlushBSS(WiFi::kMaxBSSResumeAgeSeconds + 5)); |
mukesh agrawal | 2f9df4e | 2012-08-08 12:29:20 -0700 | [diff] [blame] | 2166 | OnAfterResume(); |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 2167 | ReportScanDone(); |
| 2168 | } |
| 2169 | |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 2170 | TEST_F(WiFiMainTest, ScanTimerIdle) { |
| 2171 | StartWiFi(); |
| 2172 | dispatcher_.DispatchPendingEvents(); |
| 2173 | ReportScanDone(); |
| 2174 | CancelScanTimer(); |
| 2175 | EXPECT_TRUE(GetScanTimer().IsCancelled()); |
| 2176 | |
| 2177 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Scan(_)); |
| 2178 | FireScanTimer(); |
| 2179 | dispatcher_.DispatchPendingEvents(); |
| 2180 | EXPECT_FALSE(GetScanTimer().IsCancelled()); // Automatically re-armed. |
| 2181 | } |
| 2182 | |
| 2183 | TEST_F(WiFiMainTest, ScanTimerScanning) { |
| 2184 | StartWiFi(); |
| 2185 | dispatcher_.DispatchPendingEvents(); |
| 2186 | CancelScanTimer(); |
| 2187 | EXPECT_TRUE(GetScanTimer().IsCancelled()); |
| 2188 | |
| 2189 | // Should not call Scan, since we're already scanning. |
| 2190 | // (Scanning is triggered by StartWiFi.) |
| 2191 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Scan(_)).Times(0); |
| 2192 | FireScanTimer(); |
| 2193 | dispatcher_.DispatchPendingEvents(); |
| 2194 | EXPECT_FALSE(GetScanTimer().IsCancelled()); // Automatically re-armed. |
| 2195 | } |
| 2196 | |
| 2197 | TEST_F(WiFiMainTest, ScanTimerConnecting) { |
| 2198 | StartWiFi(); |
| 2199 | dispatcher_.DispatchPendingEvents(); |
| 2200 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 2201 | ReportScanDone(); |
| 2202 | WiFiService *service(GetServices().begin()->get()); |
| 2203 | InitiateConnect(service); |
| 2204 | CancelScanTimer(); |
| 2205 | EXPECT_TRUE(GetScanTimer().IsCancelled()); |
| 2206 | |
| 2207 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Scan(_)).Times(0); |
| 2208 | FireScanTimer(); |
| 2209 | dispatcher_.DispatchPendingEvents(); |
| 2210 | EXPECT_FALSE(GetScanTimer().IsCancelled()); // Automatically re-armed. |
| 2211 | } |
| 2212 | |
| 2213 | TEST_F(WiFiMainTest, ScanTimerReconfigured) { |
| 2214 | StartWiFi(); |
| 2215 | CancelScanTimer(); |
| 2216 | EXPECT_TRUE(GetScanTimer().IsCancelled()); |
| 2217 | |
| 2218 | SetScanInterval(1); |
| 2219 | EXPECT_FALSE(GetScanTimer().IsCancelled()); |
| 2220 | } |
| 2221 | |
| 2222 | TEST_F(WiFiMainTest, ScanTimerResetOnScanDone) { |
| 2223 | StartWiFi(); |
| 2224 | CancelScanTimer(); |
| 2225 | EXPECT_TRUE(GetScanTimer().IsCancelled()); |
| 2226 | |
| 2227 | ReportScanDone(); |
| 2228 | EXPECT_FALSE(GetScanTimer().IsCancelled()); |
| 2229 | } |
| 2230 | |
| 2231 | TEST_F(WiFiMainTest, ScanTimerStopOnZeroInterval) { |
| 2232 | StartWiFi(); |
| 2233 | EXPECT_FALSE(GetScanTimer().IsCancelled()); |
| 2234 | |
| 2235 | SetScanInterval(0); |
| 2236 | EXPECT_TRUE(GetScanTimer().IsCancelled()); |
| 2237 | } |
| 2238 | |
| 2239 | TEST_F(WiFiMainTest, ScanOnDisconnectWithHidden) { |
| 2240 | Error e; |
| 2241 | scoped_refptr<MockProfile> profile( |
| 2242 | new NiceMock<MockProfile>(control_interface(), manager(), "")); |
| 2243 | WiFiServiceRefPtr hidden_service = |
| 2244 | GetServiceInner(flimflam::kTypeWifi, "hidden_ssid", |
| 2245 | flimflam::kModeManaged, NULL, NULL, true, &e); |
| 2246 | hidden_service->set_profile(profile); |
| 2247 | |
| 2248 | StartWiFi(); |
| 2249 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 2250 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 2251 | ReportBSS("an_ap", ap->ssid_string(), ap->bssid_string(), 0, 0, |
| 2252 | kNetworkModeInfrastructure); |
| 2253 | InitiateConnect(service); |
| 2254 | ReportCurrentBSSChanged("an_ap"); |
| 2255 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 2256 | dispatcher_.DispatchPendingEvents(); |
| 2257 | |
| 2258 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), |
| 2259 | Scan(HasHiddenSSID("hidden_ssid"))); |
| 2260 | ReportCurrentBSSChanged(wpa_supplicant::kCurrentBSSNull); |
| 2261 | dispatcher_.DispatchPendingEvents(); |
| 2262 | } |
| 2263 | |
| 2264 | TEST_F(WiFiMainTest, NoScanOnDisconnectWithoutHidden) { |
| 2265 | StartWiFi(); |
| 2266 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 2267 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 2268 | ReportBSS("an_ap", ap->ssid_string(), ap->bssid_string(), 0, 0, |
| 2269 | kNetworkModeInfrastructure); |
| 2270 | InitiateConnect(service); |
| 2271 | ReportCurrentBSSChanged("an_ap"); |
| 2272 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 2273 | dispatcher_.DispatchPendingEvents(); |
| 2274 | |
| 2275 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Scan(_)).Times(0); |
| 2276 | ReportCurrentBSSChanged(wpa_supplicant::kCurrentBSSNull); |
| 2277 | dispatcher_.DispatchPendingEvents(); |
| 2278 | } |
| 2279 | |
Paul Stewart | 3c508e1 | 2012-08-09 11:40:06 -0700 | [diff] [blame] | 2280 | TEST_F(WiFiMainTest, LinkMonitorFailure) { |
| 2281 | StartWiFi(); |
| 2282 | ScopedMockLog log; |
| 2283 | EXPECT_CALL(log, Log(_, _, _)).Times(AnyNumber()); |
| 2284 | MockLinkMonitor *link_monitor = new StrictMock<MockLinkMonitor>(); |
| 2285 | SetLinkMonitor(link_monitor); |
| 2286 | EXPECT_CALL(*link_monitor, IsGatewayFound()) |
| 2287 | .WillOnce(Return(false)) |
| 2288 | .WillRepeatedly(Return(true)); |
| 2289 | EXPECT_CALL(log, Log(logging::LOG_INFO, _, |
| 2290 | EndsWith("gateway was never found."))).Times(1); |
| 2291 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Reassociate()).Times(0); |
| 2292 | OnLinkMonitorFailure(); |
| 2293 | EXPECT_CALL(log, Log(logging::LOG_INFO, _, |
| 2294 | EndsWith("Called Reassociate()."))).Times(1); |
| 2295 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Reassociate()).Times(1); |
| 2296 | OnLinkMonitorFailure(); |
| 2297 | OnSupplicantVanish(); |
| 2298 | EXPECT_CALL(log, Log(logging::LOG_ERROR, _, |
| 2299 | EndsWith("Cannot reassociate."))).Times(1); |
| 2300 | OnLinkMonitorFailure(); |
| 2301 | } |
| 2302 | |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 2303 | TEST_F(WiFiMainTest, SuspectCredentialsOpen) { |
| 2304 | Error e; |
| 2305 | WiFiServiceRefPtr service = GetOpenService( |
| 2306 | flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, &e); |
| 2307 | ReportStateChanged(wpa_supplicant::kInterfaceState4WayHandshake); |
| 2308 | EXPECT_FALSE(service->has_ever_connected()); |
| 2309 | EXPECT_FALSE(wifi()->SuspectCredentials(*service)); |
| 2310 | } |
| 2311 | |
| 2312 | TEST_F(WiFiMainTest, SuspectCredentialsWPANeverConnected) { |
| 2313 | Error e; |
| 2314 | WiFiServiceRefPtr service = |
| 2315 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 2316 | flimflam::kSecurityWpa, "abcdefgh", &e); |
| 2317 | ReportStateChanged(wpa_supplicant::kInterfaceState4WayHandshake); |
| 2318 | EXPECT_FALSE(service->has_ever_connected()); |
| 2319 | EXPECT_TRUE(wifi()->SuspectCredentials(*service)); |
| 2320 | } |
| 2321 | |
| 2322 | TEST_F(WiFiMainTest, SuspectCredentialsWPAPreviouslyConnected) { |
| 2323 | Error e; |
| 2324 | WiFiServiceRefPtr service = |
| 2325 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 2326 | flimflam::kSecurityWpa, "abcdefgh", &e); |
| 2327 | ReportStateChanged(wpa_supplicant::kInterfaceState4WayHandshake); |
| 2328 | service->has_ever_connected_ = true; |
| 2329 | EXPECT_FALSE(wifi()->SuspectCredentials(*service)); |
| 2330 | } |
| 2331 | |
| 2332 | TEST_F(WiFiMainTest, SuspectCredentialsYieldFailure) { |
| 2333 | ScopedMockLog log; |
| 2334 | Error e; |
| 2335 | MockWiFiServiceRefPtr service = MakeMockService(flimflam::kSecurityWpa); |
| 2336 | SetPendingService(service); |
| 2337 | ReportStateChanged(wpa_supplicant::kInterfaceState4WayHandshake); |
| 2338 | EXPECT_FALSE(service->has_ever_connected()); |
| 2339 | |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 2340 | EXPECT_CALL(*service, SetFailure(Service::kFailureBadPassphrase)); |
mukesh agrawal | 56e3220 | 2012-07-26 16:32:11 -0700 | [diff] [blame] | 2341 | EXPECT_CALL(*service, SetFailureSilent(_)).Times(0); |
| 2342 | EXPECT_CALL(*service, SetState(_)).Times(0); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 2343 | EXPECT_CALL(log, Log(_, _, _)).Times(AnyNumber()); |
| 2344 | EXPECT_CALL(log, Log(logging::LOG_ERROR, _, EndsWith("Bad passphrase?"))); |
| 2345 | ReportCurrentBSSChanged(wpa_supplicant::kCurrentBSSNull); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 2346 | } |
| 2347 | |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 2348 | // Scanning tests will use a mock of the event dispatcher instead of a real |
| 2349 | // one. |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 2350 | class WiFiTimerTest : public WiFiObjectTest { |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 2351 | public: |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 2352 | WiFiTimerTest() : WiFiObjectTest(&mock_dispatcher_) {} |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 2353 | |
| 2354 | protected: |
| 2355 | void ExpectInitialScanSequence(); |
| 2356 | |
| 2357 | StrictMock<MockEventDispatcher> mock_dispatcher_; |
| 2358 | }; |
| 2359 | |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 2360 | void WiFiTimerTest::ExpectInitialScanSequence() { |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 2361 | // Choose a number of iterations some multiple higher than the fast scan |
| 2362 | // count. |
| 2363 | const int kScanTimes = WiFi::kNumFastScanAttempts * 4; |
| 2364 | |
| 2365 | // Each time we call FireScanTimer() below, WiFi will post a task to actually |
| 2366 | // run Scan() on the wpa_supplicant proxy. |
| 2367 | EXPECT_CALL(mock_dispatcher_, PostTask(_)) |
| 2368 | .Times(kScanTimes); |
| 2369 | { |
| 2370 | InSequence seq; |
| 2371 | // The scans immediately after the initial scan should happen at the short |
| 2372 | // interval. If we add the initial scan (not invoked in this function) to |
| 2373 | // the ones in the expectation below, we get WiFi::kNumFastScanAttempts at |
| 2374 | // the fast scan interval. |
| 2375 | EXPECT_CALL(mock_dispatcher_, PostDelayedTask( |
| 2376 | _, WiFi::kFastScanIntervalSeconds * 1000)) |
| 2377 | .Times(WiFi::kNumFastScanAttempts - 1) |
| 2378 | .WillRepeatedly(Return(true)); |
| 2379 | |
| 2380 | // After this, the WiFi device should use the normal scan interval. |
| 2381 | EXPECT_CALL(mock_dispatcher_, PostDelayedTask( |
| 2382 | _, GetScanInterval() * 1000)) |
| 2383 | .Times(kScanTimes - WiFi::kNumFastScanAttempts + 1) |
| 2384 | .WillRepeatedly(Return(true)); |
| 2385 | |
| 2386 | for (int i = 0; i < kScanTimes; i++) { |
| 2387 | FireScanTimer(); |
| 2388 | } |
| 2389 | } |
| 2390 | } |
| 2391 | |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 2392 | TEST_F(WiFiTimerTest, FastRescan) { |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 2393 | // This PostTask is a result of the call to Scan(NULL), and is meant to |
| 2394 | // post a task to call Scan() on the wpa_supplicant proxy immediately. |
| 2395 | EXPECT_CALL(mock_dispatcher_, PostTask(_)); |
| 2396 | EXPECT_CALL(mock_dispatcher_, PostDelayedTask( |
| 2397 | _, WiFi::kFastScanIntervalSeconds * 1000)) |
| 2398 | .WillOnce(Return(true)); |
| 2399 | StartWiFi(); |
| 2400 | |
| 2401 | ExpectInitialScanSequence(); |
| 2402 | |
| 2403 | // If we end up disconnecting, the sequence should repeat. |
| 2404 | EXPECT_CALL(mock_dispatcher_, PostDelayedTask( |
| 2405 | _, WiFi::kFastScanIntervalSeconds * 1000)) |
| 2406 | .WillOnce(Return(true)); |
| 2407 | RestartFastScanAttempts(); |
| 2408 | |
| 2409 | ExpectInitialScanSequence(); |
| 2410 | } |
| 2411 | |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 2412 | TEST_F(WiFiTimerTest, ReconnectTimer) { |
| 2413 | EXPECT_CALL(mock_dispatcher_, PostTask(_)).Times(AnyNumber()); |
| 2414 | EXPECT_CALL(mock_dispatcher_, PostDelayedTask(_, _)).Times(AnyNumber()); |
| 2415 | SetupConnectedService(DBus::Path()); |
| 2416 | Mock::VerifyAndClearExpectations(&mock_dispatcher_); |
| 2417 | |
| 2418 | EXPECT_CALL(mock_dispatcher_, PostDelayedTask( |
| 2419 | _, GetReconnectTimeoutSeconds() * 1000)).Times(1); |
| 2420 | StartReconnectTimer(); |
| 2421 | Mock::VerifyAndClearExpectations(&mock_dispatcher_); |
| 2422 | StopReconnectTimer(); |
| 2423 | |
| 2424 | EXPECT_CALL(mock_dispatcher_, PostDelayedTask( |
| 2425 | _, GetReconnectTimeoutSeconds() * 1000)).Times(1); |
| 2426 | StartReconnectTimer(); |
| 2427 | Mock::VerifyAndClearExpectations(&mock_dispatcher_); |
| 2428 | GetReconnectTimeoutCallback().callback().Run(); |
| 2429 | |
| 2430 | EXPECT_CALL(mock_dispatcher_, PostDelayedTask( |
| 2431 | _, GetReconnectTimeoutSeconds() * 1000)).Times(1); |
| 2432 | StartReconnectTimer(); |
| 2433 | Mock::VerifyAndClearExpectations(&mock_dispatcher_); |
| 2434 | |
| 2435 | EXPECT_CALL(mock_dispatcher_, PostDelayedTask( |
| 2436 | _, GetReconnectTimeoutSeconds() * 1000)).Times(0); |
| 2437 | StartReconnectTimer(); |
| 2438 | } |
| 2439 | |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 2440 | TEST_F(WiFiMainTest, EAPCertification) { |
| 2441 | MockWiFiServiceRefPtr service = MakeMockService(flimflam::kSecurity8021x); |
| 2442 | EXPECT_CALL(*service, AddEAPCertification(_, _)).Times(0); |
| 2443 | |
| 2444 | ScopedMockLog log; |
| 2445 | EXPECT_CALL(log, Log(logging::LOG_ERROR, _, EndsWith("no current service."))); |
| 2446 | map<string, ::DBus::Variant> args; |
| 2447 | ReportCertification(args); |
| 2448 | Mock::VerifyAndClearExpectations(&log); |
| 2449 | |
| 2450 | SetCurrentService(service); |
| 2451 | EXPECT_CALL(log, Log(logging::LOG_ERROR, _, EndsWith("no depth parameter."))); |
| 2452 | ReportCertification(args); |
| 2453 | Mock::VerifyAndClearExpectations(&log); |
| 2454 | |
| 2455 | const uint32 kDepth = 123; |
| 2456 | args[wpa_supplicant::kInterfacePropertyDepth].writer().append_uint32(kDepth); |
| 2457 | |
| 2458 | EXPECT_CALL(log, |
| 2459 | Log(logging::LOG_ERROR, _, EndsWith("no subject parameter."))); |
| 2460 | ReportCertification(args); |
| 2461 | Mock::VerifyAndClearExpectations(&log); |
| 2462 | |
| 2463 | const string kSubject("subject"); |
| 2464 | args[wpa_supplicant::kInterfacePropertySubject].writer() |
| 2465 | .append_string(kSubject.c_str()); |
| 2466 | EXPECT_CALL(*service, AddEAPCertification(kSubject, kDepth)).Times(1); |
| 2467 | ReportCertification(args); |
| 2468 | } |
| 2469 | |
mukesh agrawal | c4f368f | 2012-06-04 19:45:52 -0700 | [diff] [blame] | 2470 | TEST_F(WiFiMainTest, PendingScanDoesNotCrashAfterStop) { |
| 2471 | // Scan is one task that should be skipped after Stop. Others are |
| 2472 | // skipped by the same mechanism (invalidating weak pointers), so we |
| 2473 | // don't test them individually. |
| 2474 | // |
| 2475 | // Note that we can't test behavior by setting expectations on the |
| 2476 | // supplicant_interface_proxy_, since that is destroyed when we StopWiFi(). |
| 2477 | StartWiFi(); |
| 2478 | StopWiFi(); |
| 2479 | dispatcher_.DispatchPendingEvents(); |
| 2480 | } |
| 2481 | |
Darin Petkov | 60ceaf3 | 2012-10-18 10:36:01 +0200 | [diff] [blame] | 2482 | TEST_F(WiFiMainTest, VerifyPaths) { |
| 2483 | string path = WiFi::kSupplicantConfPath; |
| 2484 | TrimString(path, FilePath::kSeparators, &path); |
| 2485 | EXPECT_TRUE(file_util::PathExists(FilePath(SYSROOT).Append(path))); |
| 2486 | } |
| 2487 | |
Gaurav Shah | 6d2c72d | 2012-10-16 16:30:44 -0700 | [diff] [blame] | 2488 | struct BSS { |
| 2489 | string bsspath; |
| 2490 | string ssid; |
| 2491 | string bssid; |
| 2492 | int16_t signal_strength; |
| 2493 | uint16 frequency; |
| 2494 | const char* mode; |
| 2495 | }; |
| 2496 | |
| 2497 | TEST_F(WiFiMainTest, GetGeolocationObjects) { |
| 2498 | BSS bsses[] = { |
| 2499 | {"bssid1", "ssid1", "00:00:00:00:00:00", 5, Metrics::kWiFiFrequency2412, |
| 2500 | kNetworkModeInfrastructure}, |
| 2501 | {"bssid2", "ssid2", "01:00:00:00:00:00", 30, Metrics::kWiFiFrequency5170, |
| 2502 | kNetworkModeInfrastructure}, |
| 2503 | // Same SSID but different BSSID is an additional geolocation object. |
| 2504 | {"bssid3", "ssid1", "02:00:00:00:00:00", 100, 0, |
| 2505 | kNetworkModeInfrastructure} |
| 2506 | }; |
| 2507 | StartWiFi(); |
| 2508 | vector<GeolocationInfo> objects; |
| 2509 | EXPECT_EQ(objects.size(), 0); |
| 2510 | |
| 2511 | for (size_t i = 0; i < arraysize(bsses); ++i) { |
| 2512 | ReportBSS(bsses[i].bsspath, bsses[i].ssid, bsses[i].bssid, |
| 2513 | bsses[i].signal_strength, bsses[i].frequency, bsses[i].mode); |
| 2514 | objects = wifi()->GetGeolocationObjects(); |
| 2515 | EXPECT_EQ(objects.size(), i + 1); |
| 2516 | |
| 2517 | GeolocationInfo expected_info; |
| 2518 | expected_info.AddField(kGeoMacAddressProperty, bsses[i].bssid); |
| 2519 | expected_info.AddField(kGeoSignalStrengthProperty, |
| 2520 | StringPrintf("%d", bsses[i].signal_strength)); |
| 2521 | expected_info.AddField(kGeoChannelProperty, StringPrintf( |
| 2522 | "%d", Metrics::WiFiFrequencyToChannel(bsses[i].frequency))); |
| 2523 | EXPECT_TRUE(objects[i].Equals(expected_info)); |
| 2524 | }; |
| 2525 | }; |
| 2526 | |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 2527 | } // namespace shill |