summaryrefslogtreecommitdiffstats
path: root/dbus/object_manager_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'dbus/object_manager_unittest.cc')
-rw-r--r--dbus/object_manager_unittest.cc60
1 files changed, 58 insertions, 2 deletions
diff --git a/dbus/object_manager_unittest.cc b/dbus/object_manager_unittest.cc
index 10730e1..54ddeac 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