| Index: dbus/object_manager_unittest.cc
|
| diff --git a/dbus/object_manager_unittest.cc b/dbus/object_manager_unittest.cc
|
| index 3e53095b12e4fefd7add9d87d6b31caec4b8848a..3c19fd83edd48905574bec785ea85c997f584564 100644
|
| --- a/dbus/object_manager_unittest.cc
|
| +++ b/dbus/object_manager_unittest.cc
|
| @@ -27,7 +27,7 @@ class ObjectManagerTest
|
| : public testing::Test,
|
| public ObjectManager::Interface {
|
| public:
|
| - ObjectManagerTest() {
|
| + ObjectManagerTest() : timeout_expired_(false) {
|
| }
|
|
|
| struct Properties : public PropertySet {
|
| @@ -112,6 +112,21 @@ class ObjectManagerTest
|
| message_loop_.Quit();
|
| }
|
|
|
| + // Called when an object manager has been removed from the bus.
|
| + void OnObjectManagerRemoved() {
|
| + message_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;
|
| + message_loop_.Quit();
|
| +
|
| + FAIL() << "Never received PropertiesChanged";
|
| + }
|
| +
|
| protected:
|
| // Called when an object is added.
|
| virtual void ObjectAdded(const ObjectPath& object_path,
|
| @@ -130,6 +145,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);
|
| message_loop_.Quit();
|
| }
|
| @@ -182,6 +207,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_;
|
| @@ -350,4 +378,36 @@ 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");
|
| + EXPECT_TRUE(bus_->RemoveObjectManager(
|
| + "org.chromium.TestService",
|
| + ObjectPath("/org/chromium/TestService"),
|
| + base::Bind(&ObjectManagerTest::OnObjectManagerRemoved,
|
| + base::Unretained(this))));
|
| + message_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_)
|
| + message_loop_.Run();
|
| +}
|
| +
|
| } // namespace dbus
|
|
|