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