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