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