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

Unified Diff: dbus/object_manager_unittest.cc

Issue 510863002: dbus::ObjectManager: Add a match rule for properties before GetManagedObjects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased; updated BUILD.gn; fixed crash from latest RunLoop changes Created 6 years, 3 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
« no previous file with comments | « dbus/object_manager.cc ('k') | dbus/object_proxy.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dbus/object_manager_unittest.cc
diff --git a/dbus/object_manager_unittest.cc b/dbus/object_manager_unittest.cc
index 10730e18ffbd367ba4829c0465ce061c2363bd9e..54ddeacebd4fd0cc1cdf2d15face1c45b4eb9e62 100644
--- a/dbus/object_manager_unittest.cc
+++ b/dbus/object_manager_unittest.cc
@@ -28,7 +28,7 @@ class ObjectManagerTest
: public testing::Test,
public ObjectManager::Interface {
public:
- ObjectManagerTest() {
+ ObjectManagerTest() : timeout_expired_(false) {
}
struct Properties : public PropertySet {
@@ -90,7 +90,6 @@ class ObjectManagerTest
ObjectPath("/org/chromium/TestService"));
object_manager_->RegisterInterface("org.chromium.TestInterface", this);
- object_manager_->GetManagedObjects();
WaitForObject();
}
@@ -115,6 +114,16 @@ class ObjectManagerTest
run_loop_->Quit();
}
+ // Called from the PropertiesChangedAsObjectsReceived test case. The test will
+ // not run the message loop if it receives the expected PropertiesChanged
+ // signal before the timeout. This method immediately fails the test.
+ void PropertiesChangedTestTimeout() {
+ timeout_expired_ = true;
+ run_loop_->Quit();
+
+ FAIL() << "Never received PropertiesChanged";
+ }
+
protected:
// Called when an object is added.
virtual void ObjectAdded(const ObjectPath& object_path,
@@ -133,6 +142,16 @@ class ObjectManagerTest
// Called when a property value is updated.
void OnPropertyChanged(const ObjectPath& object_path,
const std::string& name) {
+ // Store the value of the "Name" property if that's the one that
+ // changed.
+ Properties* properties = static_cast<Properties*>(
+ object_manager_->GetProperties(
+ object_path,
+ "org.chromium.TestInterface"));
+ if (name == properties->name.name())
+ last_name_value_ = properties->name.value();
+
+ // Store the updated property.
updated_properties_.push_back(name);
run_loop_->Quit();
}
@@ -191,6 +210,9 @@ class ObjectManagerTest
ObjectManager* object_manager_;
scoped_ptr<TestService> test_service_;
+ std::string last_name_value_;
+ bool timeout_expired_;
+
std::vector<std::pair<ObjectPath, std::string> > added_objects_;
std::vector<std::pair<ObjectPath, std::string> > removed_objects_;
std::vector<std::string> updated_properties_;
@@ -359,4 +381,38 @@ TEST_F(ObjectManagerTest, OwnershipLostAndRegained) {
ASSERT_EQ(1U, object_paths.size());
}
+TEST_F(ObjectManagerTest, PropertiesChangedAsObjectsReceived) {
+ // Remove the existing object manager.
+ object_manager_->UnregisterInterface("org.chromium.TestInterface");
+ run_loop_.reset(new base::RunLoop);
+ EXPECT_TRUE(bus_->RemoveObjectManager(
+ "org.chromium.TestService",
+ ObjectPath("/org/chromium/TestService"),
+ run_loop_->QuitClosure()));
+ run_loop_->Run();
+
+ PerformAction("SetSendImmediatePropertiesChanged",
+ ObjectPath("/org/chromium/TestService"));
+
+ object_manager_ = bus_->GetObjectManager(
+ "org.chromium.TestService",
+ ObjectPath("/org/chromium/TestService"));
+ object_manager_->RegisterInterface("org.chromium.TestInterface", this);
+
+ // The newly created object manager should call GetManagedObjects immediately
+ // after setting up the match rule for PropertiesChanged. We should process
+ // the PropertiesChanged event right after that. If we don't receive it within
+ // 2 seconds, then fail the test.
+ message_loop_.PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&ObjectManagerTest::PropertiesChangedTestTimeout,
+ base::Unretained(this)),
+ base::TimeDelta::FromSeconds(2));
+
+ while (last_name_value_ != "ChangedTestServiceName" && !timeout_expired_) {
+ run_loop_.reset(new base::RunLoop);
+ run_loop_->Run();
+ }
+}
+
} // namespace dbus
« no previous file with comments | « dbus/object_manager.cc ('k') | dbus/object_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698