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