shill: don't auto-connect to a disconnected service
This addresses part of the problem with the 003AsciiKeyWEP40
failure. That test establishes a connection, disconnects,
reconfigures the (WEP) password on an AP, and then tries
to reconnect.
Before this patch, the test failed as follows:
1. shill immediately tries to reconnect after the disconnect.
This reconnect uses the old password (because the test
hasn't had a chance to supply a new password).
2. The test code provides the correct password, and then
initiates an explicit connect. However, the explicit
connect is ignored, because a connection is already in
progress (to the same service).
3. The automatic reconnect fails, because it is using the
wrong password.
BUG=chromium-os:25153,chromium-os:25157
TEST=unit tests, WiFiRoaming, WiFiSecMat.*WEP*, WiFiManager
Testing notes:
- WiFiRoaming had some failures, but no regressions
- WiFiSecMat.*WEP* passed except 003CheckWEP_8021x
(previously, that failed in addition to 000StaticKeyWEP40,
001StaticKeyWEP104, 005SharedKeyWEP40, and 006SharedKeyWEP104.)
- WiFiManager passed
(previously, 003AsciiKeyWEP40 and 004AsciiKeyWEP104 failed.)
Change-Id: I2dd6312006865c914d4193ce3f7d7c5443b84deb
Reviewed-on: https://gerrit.chromium.org/gerrit/14408
Commit-Ready: mukesh agrawal <quiche@chromium.org>
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Tested-by: mukesh agrawal <quiche@chromium.org>
diff --git a/service_unittest.cc b/service_unittest.cc
index eb0c9b6..51f9d12 100644
--- a/service_unittest.cc
+++ b/service_unittest.cc
@@ -281,6 +281,28 @@
service_->set_connectable(true);
EXPECT_TRUE(service_->IsAutoConnectable());
+ // We should not auto-connect to a Service that a user has
+ // deliberately disconnected.
+ Error error;
+ service_->Disconnect(&error);
+ EXPECT_FALSE(service_->IsAutoConnectable());
+
+ // But if the Service is reloaded, it is eligible for auto-connect
+ // again.
+ NiceMock<MockStore> storage;
+ EXPECT_CALL(storage, ContainsGroup(storage_id_)).WillOnce(Return(true));
+ EXPECT_TRUE(service_->Load(&storage));
+ EXPECT_TRUE(service_->IsAutoConnectable());
+
+ // A deliberate Connect should also re-enable auto-connect.
+ service_->Disconnect(&error);
+ EXPECT_FALSE(service_->IsAutoConnectable());
+ service_->Connect(&error);
+ EXPECT_TRUE(service_->IsAutoConnectable());
+
+ // TODO(quiche): After we have resume handling in place, test that
+ // we re-enable auto-connect on resume. crosbug.com/25213
+
service_->SetState(Service::kStateConnected);
EXPECT_FALSE(service_->IsAutoConnectable());