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