Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Unified Diff: chromeos/network/shill_property_handler_unittest.cc

Issue 289383004: Merge FavoriteState into NetworkState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chromeos/network/shill_property_handler_unittest.cc
diff --git a/chromeos/network/shill_property_handler_unittest.cc b/chromeos/network/shill_property_handler_unittest.cc
index 313e1619cb48c51b7436bf41197d603069f11e1f..1b02ea54d948d10dc8310ecc1625f87cb2519302 100644
--- a/chromeos/network/shill_property_handler_unittest.cc
+++ b/chromeos/network/shill_property_handler_unittest.cc
@@ -36,20 +36,39 @@ void ErrorCallbackFunction(const std::string& error_name,
class TestListener : public internal::ShillPropertyHandler::Listener {
public:
- TestListener() : technology_list_updates_(0),
+ TestListener() : device_list_updates_(0),
+ service_list_updates_(0),
+ technology_list_updates_(0),
errors_(0) {
}
- virtual void UpdateManagedList(ManagedState::ManagedType type,
- const base::ListValue& entries) OVERRIDE {
- UpdateEntries(GetTypeString(type), entries);
+ virtual void UpdateManagedDevices(const base::ListValue& entries) OVERRIDE {
+ VLOG(1) << "UpdateManagedDevices: " << entries.GetSize();
+ UpdateEntries(shill::kDevicesProperty, entries);
+ }
+
+ virtual void UpdateManagedNetworks(const base::ListValue& entries,
+ bool complete_list) OVERRIDE {
+ VLOG(1) << "UpdateManagedNetworks(" << complete_list
+ << ") : " << entries.GetSize();
+ if (complete_list) {
+ UpdateEntries(shill::kServiceCompleteListProperty, entries);
+ } else {
+ UpdateEntries(shill::kServicesProperty, entries);
+ }
}
virtual void UpdateManagedStateProperties(
ManagedState::ManagedType type,
const std::string& path,
const base::DictionaryValue& properties) OVERRIDE {
- AddInitialPropertyUpdate(GetTypeString(type), path);
+ if (type == ManagedState::MANAGED_TYPE_NETWORK) {
+ AddInitialPropertyUpdate(shill::kServicesProperty, path);
+ } else if (type == ManagedState::MANAGED_TYPE_DEVICE) {
+ AddInitialPropertyUpdate(shill::kDevicesProperty, path);
+ } else {
+ NOTREACHED();
+ }
}
virtual void ProfileListChanged() OVERRIDE {
@@ -78,6 +97,7 @@ class TestListener : public internal::ShillPropertyHandler::Listener {
}
virtual void TechnologyListChanged() OVERRIDE {
+ VLOG(1) << "TechnologyListChanged.";
++technology_list_updates_;
}
@@ -87,7 +107,12 @@ class TestListener : public internal::ShillPropertyHandler::Listener {
virtual void ManagedStateListChanged(
ManagedState::ManagedType type) OVERRIDE {
- AddStateListUpdate(GetTypeString(type));
+ VLOG(1) << "ManagedStateListChanged: " << type;
+ if (type == ManagedState::MANAGED_TYPE_NETWORK) {
+ ++service_list_updates_;
+ } else if (type == ManagedState::MANAGED_TYPE_DEVICE) {
+ ++device_list_updates_;
+ }
}
virtual void DefaultNetworkServiceChanged(
@@ -104,25 +129,18 @@ class TestListener : public internal::ShillPropertyHandler::Listener {
const std::string& type) {
return initial_property_updates_[type];
}
- int list_updates(const std::string& type) { return list_updates_[type]; }
- void reset_list_updates() { list_updates_.clear(); }
+ int device_list_updates() { return device_list_updates_; }
+ int service_list_updates() { return service_list_updates_; }
int technology_list_updates() { return technology_list_updates_; }
+ void reset_list_updates() {
+ DVLOG(1) << "=== RESET LIST UPDATES ===";
+ device_list_updates_ = 0;
+ service_list_updates_ = 0;
+ technology_list_updates_ = 0;
+ }
int errors() { return errors_; }
private:
- std::string GetTypeString(ManagedState::ManagedType type) {
- if (type == ManagedState::MANAGED_TYPE_NETWORK) {
- return shill::kServicesProperty;
- } else if (type == ManagedState::MANAGED_TYPE_FAVORITE) {
- return shill::kServiceCompleteListProperty;
- } else if (type == ManagedState::MANAGED_TYPE_DEVICE) {
- return shill::kDevicesProperty;
- }
- LOG(ERROR) << "UpdateManagedList called with unrecognized type: " << type;
- ++errors_;
- return std::string();
- }
-
void UpdateEntries(const std::string& type, const base::ListValue& entries) {
if (type.empty())
return;
@@ -138,6 +156,7 @@ class TestListener : public internal::ShillPropertyHandler::Listener {
void AddPropertyUpdate(const std::string& type, const std::string& path) {
if (type.empty())
return;
+ VLOG(2) << "AddPropertyUpdate: " << type;
property_updates(type)[path] += 1;
}
@@ -145,22 +164,17 @@ class TestListener : public internal::ShillPropertyHandler::Listener {
const std::string& path) {
if (type.empty())
return;
+ VLOG(2) << "AddInitialPropertyUpdate: " << type;
initial_property_updates(type)[path] += 1;
}
- void AddStateListUpdate(const std::string& type) {
- if (type.empty())
- return;
- list_updates_[type] += 1;
- }
-
// Map of list-type -> paths
std::map<std::string, std::vector<std::string> > entries_;
// Map of list-type -> map of paths -> update counts
std::map<std::string, std::map<std::string, int> > property_updates_;
std::map<std::string, std::map<std::string, int> > initial_property_updates_;
- // Map of list-type -> list update counts
- std::map<std::string, int > list_updates_;
+ int device_list_updates_;
+ int service_list_updates_;
int technology_list_updates_;
int errors_;
};
@@ -207,7 +221,7 @@ class ShillPropertyHandlerTest : public testing::Test {
void AddDevice(const std::string& type, const std::string& id) {
ASSERT_TRUE(IsValidType(type));
- device_test_->AddDevice(id, type, std::string("/device/" + id));
+ device_test_->AddDevice(id, type, id);
}
void RemoveDevice(const std::string& id) {
@@ -216,18 +230,17 @@ class ShillPropertyHandlerTest : public testing::Test {
void AddService(const std::string& type,
const std::string& id,
- const std::string& state,
- bool add_to_watch_list) {
+ const std::string& state) {
ASSERT_TRUE(IsValidType(type));
service_test_->AddService(id, id, type, state,
- true /* visible */, add_to_watch_list);
+ true /* visible */,
+ true /* add_to_watch_list */);
}
void AddServiceWithIPConfig(const std::string& type,
const std::string& id,
const std::string& state,
- const std::string& ipconfig_path,
- bool add_to_watch_list) {
+ const std::string& ipconfig_path) {
ASSERT_TRUE(IsValidType(type));
service_test_->AddServiceWithIPConfig(id, /* service_path */
"" /* guid */,
@@ -236,14 +249,14 @@ class ShillPropertyHandlerTest : public testing::Test {
state,
ipconfig_path,
true /* visible */,
- add_to_watch_list);
+ true /* add_to_watch_list */);
}
void AddServiceToProfile(const std::string& type,
const std::string& id,
bool visible) {
service_test_->AddService(id, id, type, shill::kStateIdle,
- visible, false /* watch */);
+ visible, true /* watch */);
std::vector<std::string> profiles;
profile_test_->GetProfilePaths(&profiles);
ASSERT_TRUE(profiles.size() > 0);
@@ -281,15 +294,10 @@ class ShillPropertyHandlerTest : public testing::Test {
AddDevice(shill::kTypeWifi, "stub_wifi_device1");
AddDevice(shill::kTypeCellular, "stub_cellular_device1");
service_test_->ClearServices();
- const bool add_to_watchlist = true;
- AddService(shill::kTypeEthernet, "stub_ethernet",
- shill::kStateOnline, add_to_watchlist);
- AddService(shill::kTypeWifi, "stub_wifi1",
- shill::kStateOnline, add_to_watchlist);
- AddService(shill::kTypeWifi, "stub_wifi2",
- shill::kStateIdle, add_to_watchlist);
- AddService(shill::kTypeCellular, "stub_cellular1",
- shill::kStateIdle, add_to_watchlist);
+ AddService(shill::kTypeEthernet, "stub_ethernet", shill::kStateOnline);
+ AddService(shill::kTypeWifi, "stub_wifi1", shill::kStateOnline);
+ AddService(shill::kTypeWifi, "stub_wifi2", shill::kStateIdle);
+ AddService(shill::kTypeCellular, "stub_cellular1", shill::kStateIdle);
}
base::MessageLoopForUI message_loop_;
@@ -322,27 +330,28 @@ TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerTechnologyChanged) {
EXPECT_EQ(initial_technology_updates, listener_->technology_list_updates());
// Remove an enabled technology. Updates both the Available and Enabled lists.
+ listener_->reset_list_updates();
manager_test_->RemoveTechnology(shill::kTypeWifi);
message_loop_.RunUntilIdle();
- EXPECT_EQ(initial_technology_updates + 2,
- listener_->technology_list_updates());
+ EXPECT_EQ(2, listener_->technology_list_updates());
// Add a disabled technology.
+ listener_->reset_list_updates();
manager_test_->AddTechnology(shill::kTypeWifi, false);
message_loop_.RunUntilIdle();
- EXPECT_EQ(initial_technology_updates + 3,
- listener_->technology_list_updates());
+ EXPECT_EQ(1, listener_->technology_list_updates());
EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable(
shill::kTypeWifi));
EXPECT_FALSE(shill_property_handler_->IsTechnologyEnabled(shill::kTypeWifi));
- // Enable the technology.
+ // Enable the technology. This will add new services which will request a
+ // manager update, triggering a total of 3 new updates.
+ listener_->reset_list_updates();
DBusThreadManager::Get()->GetShillManagerClient()->EnableTechnology(
shill::kTypeWifi,
base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
message_loop_.RunUntilIdle();
- EXPECT_EQ(initial_technology_updates + 4,
- listener_->technology_list_updates());
+ EXPECT_EQ(3, listener_->technology_list_updates());
EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled(shill::kTypeWifi));
EXPECT_EQ(0, listener_->errors());
@@ -357,15 +366,15 @@ TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerDevicePropertyChanged) {
const std::string kTestDevicePath("test_wifi_device1");
AddDevice(shill::kTypeWifi, kTestDevicePath);
message_loop_.RunUntilIdle();
- EXPECT_EQ(1, listener_->list_updates(shill::kDevicesProperty));
+ EXPECT_EQ(1, listener_->device_list_updates());
EXPECT_EQ(kNumShillManagerClientStubImplDevices + 1,
listener_->entries(shill::kDevicesProperty).size());
- // Device changes are not observed.
+
// Remove a device
listener_->reset_list_updates();
RemoveDevice(kTestDevicePath);
message_loop_.RunUntilIdle();
- EXPECT_EQ(1, listener_->list_updates(shill::kDevicesProperty));
+ EXPECT_EQ(1, listener_->device_list_updates());
EXPECT_EQ(kNumShillManagerClientStubImplDevices,
listener_->entries(shill::kDevicesProperty).size());
@@ -377,13 +386,13 @@ TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServicePropertyChanged) {
EXPECT_EQ(kNumShillManagerClientStubImplServices,
listener_->entries(shill::kServicesProperty).size());
- // Add an unwatched service.
+ // Add a service.
listener_->reset_list_updates();
const std::string kTestServicePath("test_wifi_service1");
- AddService(shill::kTypeWifi, kTestServicePath, shill::kStateIdle, false);
+ AddService(shill::kTypeWifi, kTestServicePath, shill::kStateIdle);
message_loop_.RunUntilIdle();
- // Watched and unwatched services trigger a service list update.
- EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty));
+ // Add should trigger a service list update and update entries.
+ EXPECT_EQ(1, listener_->service_list_updates());
EXPECT_EQ(kNumShillManagerClientStubImplServices + 1,
listener_->entries(shill::kServicesProperty).size());
// Service receives an initial property update.
@@ -397,36 +406,15 @@ TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServicePropertyChanged) {
scan_interval,
base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
message_loop_.RunUntilIdle();
- // Property change triggers an update.
+ // Property change triggers an update (but not a service list update).
EXPECT_EQ(1, listener_->property_updates(
shill::kServicesProperty)[kTestServicePath]);
- // Add the existing service to the watch list.
- listener_->reset_list_updates();
- AddService(shill::kTypeWifi, kTestServicePath, shill::kStateIdle, true);
- message_loop_.RunUntilIdle();
- // Service list update should be received when watch list changes.
- EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty));
- // Number of services shouldn't change.
- EXPECT_EQ(kNumShillManagerClientStubImplServices + 1,
- listener_->entries(shill::kServicesProperty).size());
-
- // Change a property.
- DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
- dbus::ObjectPath(kTestServicePath),
- shill::kScanIntervalProperty,
- scan_interval,
- base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
- message_loop_.RunUntilIdle();
- // Property change should trigger another update.
- EXPECT_EQ(2, listener_->property_updates(
- shill::kServicesProperty)[kTestServicePath]);
-
- // Remove a service
+ // Remove a service. This will update the entries but will not signal a
+ // service list update since no new services need to be requested.
listener_->reset_list_updates();
RemoveService(kTestServicePath);
message_loop_.RunUntilIdle();
- EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty));
EXPECT_EQ(kNumShillManagerClientStubImplServices,
listener_->entries(shill::kServicesProperty).size());
@@ -464,7 +452,7 @@ TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerIPConfigPropertyChanged) {
// Add a service with an empty ipconfig and then update
// its ipconfig property.
const std::string kTestServicePath1("test_wifi_service1");
- AddService(shill::kTypeWifi, kTestServicePath1, shill::kStateIdle, true);
+ AddService(shill::kTypeWifi, kTestServicePath1, shill::kStateIdle);
message_loop_.RunUntilIdle();
// This is the initial property update.
EXPECT_EQ(1, listener_->initial_property_updates(
@@ -479,76 +467,52 @@ TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerIPConfigPropertyChanged) {
EXPECT_EQ(1, listener_->property_updates(
shill::kIPConfigsProperty)[kTestIPConfigPath]);
- // Now, Add a new watched service with the IPConfig already set.
+ // Now, Add a new service with the IPConfig already set.
const std::string kTestServicePath2("test_wifi_service2");
AddServiceWithIPConfig(shill::kTypeWifi, kTestServicePath2,
- shill::kStateIdle, kTestIPConfigPath, true);
+ shill::kStateIdle, kTestIPConfigPath);
message_loop_.RunUntilIdle();
- // A watched service with the IPConfig property already set should trigger an
+ // A service with the IPConfig property already set should trigger an
// additional IPConfigs update.
EXPECT_EQ(2, listener_->property_updates(
shill::kIPConfigsProperty)[kTestIPConfigPath]);
}
-TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServiceCompleteList) {
- // Add a new entry to the profile only (triggers a Services update).
+TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServiceList) {
+ // Add an entry to the profile only.
const std::string kTestServicePath1("stub_wifi_profile_only1");
- AddServiceToProfile(shill::kTypeWifi, kTestServicePath1, false);
+ AddServiceToProfile(shill::kTypeWifi, kTestServicePath1, false /* visible */);
message_loop_.RunUntilIdle();
// Update the Manager properties. This should trigger a single list update
- // for both Services and ServiceCompleteList, and a single property update
- // for ServiceCompleteList.
+ // and a single initial property update.
listener_->reset_list_updates();
shill_property_handler_->UpdateManagerProperties();
message_loop_.RunUntilIdle();
- EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty));
- EXPECT_EQ(1, listener_->list_updates(shill::kServiceCompleteListProperty));
- EXPECT_EQ(0, listener_->initial_property_updates(
- shill::kServicesProperty)[kTestServicePath1]);
+ EXPECT_EQ(1, listener_->service_list_updates());
EXPECT_EQ(1, listener_->initial_property_updates(
- shill::kServiceCompleteListProperty)[kTestServicePath1]);
+ shill::kServicesProperty)[kTestServicePath1]);
+
+ EXPECT_EQ(0, listener_->property_updates(
+ shill::kServicesProperty)[kTestServicePath1]);
EXPECT_EQ(0, listener_->property_updates(
shill::kServicesProperty)[kTestServicePath1]);
+
EXPECT_EQ(0, listener_->property_updates(
shill::kServiceCompleteListProperty)[kTestServicePath1]);
// Add a new entry to the services and the profile; should also trigger a
- // single list update for both Services and ServiceCompleteList, and should
- // trigger tow property updates for Services (one when the Profile propety
- // changes, and one for the Request) and one ServiceCompleteList change for
- // the Request.
+ // service lis tupdate, and a property update.
listener_->reset_list_updates();
const std::string kTestServicePath2("stub_wifi_profile_only2");
AddServiceToProfile(shill::kTypeWifi, kTestServicePath2, true);
shill_property_handler_->UpdateManagerProperties();
message_loop_.RunUntilIdle();
- EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty));
- EXPECT_EQ(1, listener_->list_updates(shill::kServiceCompleteListProperty));
+ EXPECT_EQ(1, listener_->service_list_updates());
EXPECT_EQ(1, listener_->initial_property_updates(
shill::kServicesProperty)[kTestServicePath2]);
- EXPECT_EQ(1, listener_->initial_property_updates(
- shill::kServiceCompleteListProperty)[kTestServicePath2]);
- // Expect one property update for the Profile property of the Network.
EXPECT_EQ(1, listener_->property_updates(
shill::kServicesProperty)[kTestServicePath2]);
- EXPECT_EQ(0, listener_->property_updates(
- shill::kServiceCompleteListProperty)[kTestServicePath2]);
-
- // Change a property of a Network in a Profile.
- base::FundamentalValue scan_interval(3);
- DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
- dbus::ObjectPath(kTestServicePath2),
- shill::kScanIntervalProperty,
- scan_interval,
- base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
- message_loop_.RunUntilIdle();
- // Property change should trigger an update for the Network only; no
- // property updates pushed by Shill affect Favorites.
- EXPECT_EQ(2, listener_->property_updates(
- shill::kServicesProperty)[kTestServicePath2]);
- EXPECT_EQ(0, listener_->property_updates(
- shill::kServiceCompleteListProperty)[kTestServicePath2]);
}
} // namespace chromeos
« chromeos/network/network_state_handler.cc ('K') | « chromeos/network/shill_property_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698