shill: Give Ethernet services an affinity to the default profile
When an ethernet service is created, save it to the default profile
by default. This way, if static IP parameters are assigned to it,
it is shared globally instead of for only the logged-in. This is
a reasonable default for services that are enabled by a physical
connection. RPC callers are free to reassign the ethernet service
to a different profile, and this selection will be honored going
forwards.
BUG=chromium-os:23930
TEST=New unit tests; manual -- plug in ethernet while logged in and
ensure ethernet is added to the global profile.
Change-Id: I24e71bacc8c4bd015c2cdbb0039eb54d85dc5b65
Reviewed-on: https://gerrit.chromium.org/gerrit/21524
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
Commit-Ready: Paul Stewart <pstew@chromium.org>
diff --git a/default_profile_unittest.cc b/default_profile_unittest.cc
index 301dfd4..ac4edb0 100644
--- a/default_profile_unittest.cc
+++ b/default_profile_unittest.cc
@@ -18,6 +18,7 @@
#include "shill/manager.h"
#include "shill/mock_control.h"
#include "shill/mock_device.h"
+#include "shill/mock_service.h"
#include "shill/mock_store.h"
#include "shill/portal_detector.h"
#include "shill/property_store_unittest.h"
@@ -219,4 +220,35 @@
EXPECT_EQ(storage_path() + "/default.profile", path.value());
}
+TEST_F(DefaultProfileTest, ConfigureService) {
+ scoped_ptr<MockStore> storage(new MockStore);
+ EXPECT_CALL(*storage, ContainsGroup(_))
+ .WillRepeatedly(Return(false));
+ EXPECT_CALL(*storage, Flush())
+ .WillOnce(Return(true));
+
+ scoped_refptr<MockService> unknown_service(new MockService(
+ control_interface(),
+ dispatcher(),
+ metrics(),
+ manager()));
+ EXPECT_CALL(*unknown_service, technology())
+ .WillOnce(Return(Technology::kUnknown));
+ EXPECT_CALL(*unknown_service, Save(_)) .Times(0);
+
+ scoped_refptr<MockService> ethernet_service(new MockService(
+ control_interface(),
+ dispatcher(),
+ metrics(),
+ manager()));
+ EXPECT_CALL(*ethernet_service, technology())
+ .WillOnce(Return(Technology::kEthernet));
+ EXPECT_CALL(*ethernet_service, Save(storage.get()))
+ .WillOnce(Return(true));
+
+ profile_->set_storage(storage.release());
+ EXPECT_FALSE(profile_->ConfigureService(unknown_service));
+ EXPECT_TRUE(profile_->ConfigureService(ethernet_service));
+}
+
} // namespace shill