blob: 427c4b018e5d4fd1971a4ed2f0aa04d82fe19083 [file] [log] [blame]
[email protected]9cc40cb2013-03-25 18:20:081// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "dbus/object_manager.h"
6
avi22437c692015-12-22 18:12:457#include <stddef.h>
8#include <stdint.h>
9
[email protected]9cc40cb2013-03-25 18:20:0810#include <string>
11#include <vector>
12
[email protected]9cc40cb2013-03-25 18:20:0813#include "base/bind.h"
Carlos Caballerodd8bf7b042019-07-30 14:14:1514#include "base/message_loop/message_pump_type.h"
earthdok9562caf2014-09-03 10:32:3615#include "base/run_loop.h"
fdoray6ef45cf2016-08-25 15:36:3716#include "base/single_thread_task_runner.h"
Gabriel Charettec7108742019-08-23 03:31:4017#include "base/test/task_environment.h"
[email protected]9cc40cb2013-03-25 18:20:0818#include "base/threading/thread.h"
19#include "base/threading/thread_restrictions.h"
20#include "dbus/bus.h"
21#include "dbus/object_path.h"
22#include "dbus/object_proxy.h"
23#include "dbus/property.h"
24#include "dbus/test_service.h"
25#include "testing/gtest/include/gtest/gtest.h"
26
[email protected]2a57ca642013-06-13 06:37:1927namespace dbus {
28
[email protected]9cc40cb2013-03-25 18:20:0829// The object manager test exercises the asynchronous APIs in ObjectManager,
30// and by extension PropertySet and Property<>.
31class ObjectManagerTest
32 : public testing::Test,
[email protected]2a57ca642013-06-13 06:37:1933 public ObjectManager::Interface {
[email protected]9cc40cb2013-03-25 18:20:0834 public:
armansitoebff093d2014-09-05 17:49:3435 ObjectManagerTest() : timeout_expired_(false) {
[email protected]9cc40cb2013-03-25 18:20:0836 }
37
[email protected]2a57ca642013-06-13 06:37:1938 struct Properties : public PropertySet {
39 Property<std::string> name;
avi22437c692015-12-22 18:12:4540 Property<int16_t> version;
Ben Chanc7c9c762017-11-08 01:50:2141 Property<std::vector<std::string>> methods;
42 Property<std::vector<ObjectPath>> objects;
[email protected]9cc40cb2013-03-25 18:20:0843
[email protected]2a57ca642013-06-13 06:37:1944 Properties(ObjectProxy* object_proxy,
[email protected]9cc40cb2013-03-25 18:20:0845 const std::string& interface_name,
46 PropertyChangedCallback property_changed_callback)
[email protected]2a57ca642013-06-13 06:37:1947 : PropertySet(object_proxy, interface_name, property_changed_callback) {
[email protected]9cc40cb2013-03-25 18:20:0848 RegisterProperty("Name", &name);
49 RegisterProperty("Version", &version);
50 RegisterProperty("Methods", &methods);
51 RegisterProperty("Objects", &objects);
52 }
53 };
54
dcheng3bb7119c2014-12-29 18:30:1755 PropertySet* CreateProperties(ObjectProxy* object_proxy,
56 const ObjectPath& object_path,
57 const std::string& interface_name) override {
[email protected]9cc40cb2013-03-25 18:20:0858 Properties* properties = new Properties(
59 object_proxy, interface_name,
Reilly Grantd4e66132019-11-22 17:14:5060 base::BindRepeating(&ObjectManagerTest::OnPropertyChanged,
61 base::Unretained(this), object_path));
[email protected]2a57ca642013-06-13 06:37:1962 return static_cast<PropertySet*>(properties);
[email protected]9cc40cb2013-03-25 18:20:0863 }
64
dcheng3bb7119c2014-12-29 18:30:1765 void SetUp() override {
[email protected]9cc40cb2013-03-25 18:20:0866 // Make the main thread not to allow IO.
67 base::ThreadRestrictions::SetIOAllowed(false);
68
69 // Start the D-Bus thread.
70 dbus_thread_.reset(new base::Thread("D-Bus Thread"));
71 base::Thread::Options thread_options;
Carlos Caballerodd8bf7b042019-07-30 14:14:1572 thread_options.message_pump_type = base::MessagePumpType::IO;
[email protected]9cc40cb2013-03-25 18:20:0873 ASSERT_TRUE(dbus_thread_->StartWithOptions(thread_options));
74
75 // Start the test service, using the D-Bus thread.
[email protected]2a57ca642013-06-13 06:37:1976 TestService::Options options;
skyostil8a033aa2015-06-17 15:46:0477 options.dbus_task_runner = dbus_thread_->task_runner();
[email protected]2a57ca642013-06-13 06:37:1978 test_service_.reset(new TestService(options));
[email protected]9cc40cb2013-03-25 18:20:0879 ASSERT_TRUE(test_service_->StartService());
Ryo Hashimoto3bbeb5c2018-08-13 04:58:3980 test_service_->WaitUntilServiceIsStarted();
[email protected]9cc40cb2013-03-25 18:20:0881 ASSERT_TRUE(test_service_->HasDBusThread());
82
83 // Create the client, using the D-Bus thread.
[email protected]2a57ca642013-06-13 06:37:1984 Bus::Options bus_options;
85 bus_options.bus_type = Bus::SESSION;
86 bus_options.connection_type = Bus::PRIVATE;
skyostil8a033aa2015-06-17 15:46:0487 bus_options.dbus_task_runner = dbus_thread_->task_runner();
[email protected]2a57ca642013-06-13 06:37:1988 bus_ = new Bus(bus_options);
[email protected]9cc40cb2013-03-25 18:20:0889 ASSERT_TRUE(bus_->HasDBusThread());
90
91 object_manager_ = bus_->GetObjectManager(
hashimoto067d84f522016-01-05 08:48:0392 test_service_->service_name(),
[email protected]2a57ca642013-06-13 06:37:1993 ObjectPath("/org/chromium/TestService"));
[email protected]9cc40cb2013-03-25 18:20:0894 object_manager_->RegisterInterface("org.chromium.TestInterface", this);
95
[email protected]9cc40cb2013-03-25 18:20:0896 WaitForObject();
97 }
98
dcheng3bb7119c2014-12-29 18:30:1799 void TearDown() override {
[email protected]9cc40cb2013-03-25 18:20:08100 bus_->ShutdownOnDBusThreadAndBlock();
101
102 // Shut down the service.
103 test_service_->ShutdownAndBlock();
104
105 // Reset to the default.
106 base::ThreadRestrictions::SetIOAllowed(true);
107
108 // Stopping a thread is considered an IO operation, so do this after
109 // allowing IO.
110 test_service_->Stop();
earthdok9562caf2014-09-03 10:32:36111
112 base::RunLoop().RunUntilIdle();
[email protected]9cc40cb2013-03-25 18:20:08113 }
114
[email protected]2a57ca642013-06-13 06:37:19115 void MethodCallback(Response* response) {
[email protected]9cc40cb2013-03-25 18:20:08116 method_callback_called_ = true;
earthdok9562caf2014-09-03 10:32:36117 run_loop_->Quit();
[email protected]9cc40cb2013-03-25 18:20:08118 }
119
armansitoebff093d2014-09-05 17:49:34120 // Called from the PropertiesChangedAsObjectsReceived test case. The test will
121 // not run the message loop if it receives the expected PropertiesChanged
122 // signal before the timeout. This method immediately fails the test.
123 void PropertiesChangedTestTimeout() {
124 timeout_expired_ = true;
125 run_loop_->Quit();
126
127 FAIL() << "Never received PropertiesChanged";
128 }
129
[email protected]2a57ca642013-06-13 06:37:19130 protected:
[email protected]9cc40cb2013-03-25 18:20:08131 // Called when an object is added.
dcheng3bb7119c2014-12-29 18:30:17132 void ObjectAdded(const ObjectPath& object_path,
133 const std::string& interface_name) override {
[email protected]9cc40cb2013-03-25 18:20:08134 added_objects_.push_back(std::make_pair(object_path, interface_name));
earthdok9562caf2014-09-03 10:32:36135 run_loop_->Quit();
[email protected]9cc40cb2013-03-25 18:20:08136 }
137
138 // Called when an object is removed.
dcheng3bb7119c2014-12-29 18:30:17139 void ObjectRemoved(const ObjectPath& object_path,
140 const std::string& interface_name) override {
[email protected]9cc40cb2013-03-25 18:20:08141 removed_objects_.push_back(std::make_pair(object_path, interface_name));
earthdok9562caf2014-09-03 10:32:36142 run_loop_->Quit();
[email protected]9cc40cb2013-03-25 18:20:08143 }
144
145 // Called when a property value is updated.
[email protected]2a57ca642013-06-13 06:37:19146 void OnPropertyChanged(const ObjectPath& object_path,
[email protected]9cc40cb2013-03-25 18:20:08147 const std::string& name) {
armansitoebff093d2014-09-05 17:49:34148 // Store the value of the "Name" property if that's the one that
149 // changed.
150 Properties* properties = static_cast<Properties*>(
151 object_manager_->GetProperties(
152 object_path,
153 "org.chromium.TestInterface"));
154 if (name == properties->name.name())
155 last_name_value_ = properties->name.value();
156
157 // Store the updated property.
[email protected]9cc40cb2013-03-25 18:20:08158 updated_properties_.push_back(name);
earthdok9562caf2014-09-03 10:32:36159 run_loop_->Quit();
[email protected]9cc40cb2013-03-25 18:20:08160 }
161
162 static const size_t kExpectedObjects = 1;
163 static const size_t kExpectedProperties = 4;
164
165 void WaitForObject() {
166 while (added_objects_.size() < kExpectedObjects ||
earthdok9562caf2014-09-03 10:32:36167 updated_properties_.size() < kExpectedProperties) {
168 run_loop_.reset(new base::RunLoop);
169 run_loop_->Run();
170 }
[email protected]9cc40cb2013-03-25 18:20:08171 for (size_t i = 0; i < kExpectedObjects; ++i)
172 added_objects_.erase(added_objects_.begin());
173 for (size_t i = 0; i < kExpectedProperties; ++i)
174 updated_properties_.erase(updated_properties_.begin());
175 }
176
177 void WaitForRemoveObject() {
earthdok9562caf2014-09-03 10:32:36178 while (removed_objects_.size() < kExpectedObjects) {
179 run_loop_.reset(new base::RunLoop);
180 run_loop_->Run();
181 }
[email protected]9cc40cb2013-03-25 18:20:08182 for (size_t i = 0; i < kExpectedObjects; ++i)
183 removed_objects_.erase(removed_objects_.begin());
184 }
185
186 void WaitForMethodCallback() {
earthdok9562caf2014-09-03 10:32:36187 run_loop_.reset(new base::RunLoop);
188 run_loop_->Run();
[email protected]9cc40cb2013-03-25 18:20:08189 method_callback_called_ = false;
190 }
191
[email protected]2a57ca642013-06-13 06:37:19192 void PerformAction(const std::string& action, const ObjectPath& object_path) {
193 ObjectProxy* object_proxy = bus_->GetObjectProxy(
hashimoto067d84f522016-01-05 08:48:03194 test_service_->service_name(),
[email protected]2a57ca642013-06-13 06:37:19195 ObjectPath("/org/chromium/TestObject"));
[email protected]9cc40cb2013-03-25 18:20:08196
[email protected]2a57ca642013-06-13 06:37:19197 MethodCall method_call("org.chromium.TestInterface", "PerformAction");
198 MessageWriter writer(&method_call);
[email protected]9cc40cb2013-03-25 18:20:08199 writer.AppendString(action);
200 writer.AppendObjectPath(object_path);
201
Reilly Grantd4e66132019-11-22 17:14:50202 object_proxy->CallMethod(&method_call, ObjectProxy::TIMEOUT_USE_DEFAULT,
203 base::BindOnce(&ObjectManagerTest::MethodCallback,
204 base::Unretained(this)));
[email protected]9cc40cb2013-03-25 18:20:08205 WaitForMethodCallback();
206 }
207
Gabriel Charette1858a232019-09-09 07:50:49208 base::test::SingleThreadTaskEnvironment task_environment_;
dcheng2a193282016-04-08 22:55:04209 std::unique_ptr<base::RunLoop> run_loop_;
210 std::unique_ptr<base::Thread> dbus_thread_;
[email protected]2a57ca642013-06-13 06:37:19211 scoped_refptr<Bus> bus_;
212 ObjectManager* object_manager_;
dcheng2a193282016-04-08 22:55:04213 std::unique_ptr<TestService> test_service_;
[email protected]9cc40cb2013-03-25 18:20:08214
armansitoebff093d2014-09-05 17:49:34215 std::string last_name_value_;
216 bool timeout_expired_;
217
Ben Chanc7c9c762017-11-08 01:50:21218 std::vector<std::pair<ObjectPath, std::string>> added_objects_;
219 std::vector<std::pair<ObjectPath, std::string>> removed_objects_;
[email protected]9cc40cb2013-03-25 18:20:08220 std::vector<std::string> updated_properties_;
221
222 bool method_callback_called_;
223};
224
225
226TEST_F(ObjectManagerTest, InitialObject) {
[email protected]2a57ca642013-06-13 06:37:19227 ObjectProxy* object_proxy = object_manager_->GetObjectProxy(
228 ObjectPath("/org/chromium/TestObject"));
Ben Chan14d50032017-11-09 20:20:16229 EXPECT_NE(nullptr, object_proxy);
[email protected]9cc40cb2013-03-25 18:20:08230
231 Properties* properties = static_cast<Properties*>(
[email protected]2a57ca642013-06-13 06:37:19232 object_manager_->GetProperties(ObjectPath("/org/chromium/TestObject"),
233 "org.chromium.TestInterface"));
Ben Chan14d50032017-11-09 20:20:16234 EXPECT_NE(nullptr, properties);
[email protected]9cc40cb2013-03-25 18:20:08235
236 EXPECT_EQ("TestService", properties->name.value());
237 EXPECT_EQ(10, properties->version.value());
238
239 std::vector<std::string> methods = properties->methods.value();
240 ASSERT_EQ(4U, methods.size());
241 EXPECT_EQ("Echo", methods[0]);
242 EXPECT_EQ("SlowEcho", methods[1]);
243 EXPECT_EQ("AsyncEcho", methods[2]);
244 EXPECT_EQ("BrokenMethod", methods[3]);
245
[email protected]2a57ca642013-06-13 06:37:19246 std::vector<ObjectPath> objects = properties->objects.value();
[email protected]9cc40cb2013-03-25 18:20:08247 ASSERT_EQ(1U, objects.size());
[email protected]2a57ca642013-06-13 06:37:19248 EXPECT_EQ(ObjectPath("/TestObjectPath"), objects[0]);
[email protected]9cc40cb2013-03-25 18:20:08249}
250
251TEST_F(ObjectManagerTest, UnknownObjectProxy) {
[email protected]2a57ca642013-06-13 06:37:19252 ObjectProxy* object_proxy = object_manager_->GetObjectProxy(
253 ObjectPath("/org/chromium/UnknownObject"));
Ben Chan14d50032017-11-09 20:20:16254 EXPECT_EQ(nullptr, object_proxy);
[email protected]9cc40cb2013-03-25 18:20:08255}
256
257TEST_F(ObjectManagerTest, UnknownObjectProperties) {
258 Properties* properties = static_cast<Properties*>(
[email protected]2a57ca642013-06-13 06:37:19259 object_manager_->GetProperties(ObjectPath("/org/chromium/UnknownObject"),
260 "org.chromium.TestInterface"));
Ben Chan14d50032017-11-09 20:20:16261 EXPECT_EQ(nullptr, properties);
[email protected]9cc40cb2013-03-25 18:20:08262}
263
264TEST_F(ObjectManagerTest, UnknownInterfaceProperties) {
265 Properties* properties = static_cast<Properties*>(
[email protected]2a57ca642013-06-13 06:37:19266 object_manager_->GetProperties(ObjectPath("/org/chromium/TestObject"),
267 "org.chromium.UnknownService"));
Ben Chan14d50032017-11-09 20:20:16268 EXPECT_EQ(nullptr, properties);
[email protected]9cc40cb2013-03-25 18:20:08269}
270
271TEST_F(ObjectManagerTest, GetObjects) {
[email protected]2a57ca642013-06-13 06:37:19272 std::vector<ObjectPath> object_paths = object_manager_->GetObjects();
[email protected]9cc40cb2013-03-25 18:20:08273 ASSERT_EQ(1U, object_paths.size());
[email protected]2a57ca642013-06-13 06:37:19274 EXPECT_EQ(ObjectPath("/org/chromium/TestObject"), object_paths[0]);
[email protected]9cc40cb2013-03-25 18:20:08275}
276
277TEST_F(ObjectManagerTest, GetObjectsWithInterface) {
[email protected]2a57ca642013-06-13 06:37:19278 std::vector<ObjectPath> object_paths =
[email protected]9cc40cb2013-03-25 18:20:08279 object_manager_->GetObjectsWithInterface("org.chromium.TestInterface");
280 ASSERT_EQ(1U, object_paths.size());
[email protected]2a57ca642013-06-13 06:37:19281 EXPECT_EQ(ObjectPath("/org/chromium/TestObject"), object_paths[0]);
[email protected]9cc40cb2013-03-25 18:20:08282}
283
284TEST_F(ObjectManagerTest, GetObjectsWithUnknownInterface) {
[email protected]2a57ca642013-06-13 06:37:19285 std::vector<ObjectPath> object_paths =
[email protected]9cc40cb2013-03-25 18:20:08286 object_manager_->GetObjectsWithInterface("org.chromium.UnknownService");
287 EXPECT_EQ(0U, object_paths.size());
288}
289
290TEST_F(ObjectManagerTest, SameObject) {
[email protected]2a57ca642013-06-13 06:37:19291 ObjectManager* object_manager = bus_->GetObjectManager(
hashimoto067d84f522016-01-05 08:48:03292 test_service_->service_name(),
[email protected]2a57ca642013-06-13 06:37:19293 ObjectPath("/org/chromium/TestService"));
[email protected]9cc40cb2013-03-25 18:20:08294 EXPECT_EQ(object_manager_, object_manager);
295}
296
297TEST_F(ObjectManagerTest, DifferentObjectForService) {
[email protected]2a57ca642013-06-13 06:37:19298 ObjectManager* object_manager = bus_->GetObjectManager(
[email protected]9cc40cb2013-03-25 18:20:08299 "org.chromium.DifferentService",
[email protected]2a57ca642013-06-13 06:37:19300 ObjectPath("/org/chromium/TestService"));
[email protected]9cc40cb2013-03-25 18:20:08301 EXPECT_NE(object_manager_, object_manager);
302}
303
304TEST_F(ObjectManagerTest, DifferentObjectForPath) {
[email protected]2a57ca642013-06-13 06:37:19305 ObjectManager* object_manager = bus_->GetObjectManager(
hashimoto067d84f522016-01-05 08:48:03306 test_service_->service_name(),
[email protected]2a57ca642013-06-13 06:37:19307 ObjectPath("/org/chromium/DifferentService"));
[email protected]9cc40cb2013-03-25 18:20:08308 EXPECT_NE(object_manager_, object_manager);
309}
310
311TEST_F(ObjectManagerTest, SecondObject) {
[email protected]2a57ca642013-06-13 06:37:19312 PerformAction("AddObject", ObjectPath("/org/chromium/SecondObject"));
[email protected]9cc40cb2013-03-25 18:20:08313 WaitForObject();
314
[email protected]2a57ca642013-06-13 06:37:19315 ObjectProxy* object_proxy = object_manager_->GetObjectProxy(
316 ObjectPath("/org/chromium/SecondObject"));
Ben Chan14d50032017-11-09 20:20:16317 EXPECT_NE(nullptr, object_proxy);
[email protected]9cc40cb2013-03-25 18:20:08318
319 Properties* properties = static_cast<Properties*>(
[email protected]2a57ca642013-06-13 06:37:19320 object_manager_->GetProperties(ObjectPath("/org/chromium/SecondObject"),
321 "org.chromium.TestInterface"));
Ben Chan14d50032017-11-09 20:20:16322 EXPECT_NE(nullptr, properties);
[email protected]9cc40cb2013-03-25 18:20:08323
[email protected]2a57ca642013-06-13 06:37:19324 std::vector<ObjectPath> object_paths = object_manager_->GetObjects();
[email protected]9cc40cb2013-03-25 18:20:08325 ASSERT_EQ(2U, object_paths.size());
326
327 std::sort(object_paths.begin(), object_paths.end());
[email protected]2a57ca642013-06-13 06:37:19328 EXPECT_EQ(ObjectPath("/org/chromium/SecondObject"), object_paths[0]);
329 EXPECT_EQ(ObjectPath("/org/chromium/TestObject"), object_paths[1]);
[email protected]9cc40cb2013-03-25 18:20:08330
331 object_paths =
332 object_manager_->GetObjectsWithInterface("org.chromium.TestInterface");
333 ASSERT_EQ(2U, object_paths.size());
334
335 std::sort(object_paths.begin(), object_paths.end());
[email protected]2a57ca642013-06-13 06:37:19336 EXPECT_EQ(ObjectPath("/org/chromium/SecondObject"), object_paths[0]);
337 EXPECT_EQ(ObjectPath("/org/chromium/TestObject"), object_paths[1]);
[email protected]9cc40cb2013-03-25 18:20:08338}
339
340TEST_F(ObjectManagerTest, RemoveSecondObject) {
[email protected]2a57ca642013-06-13 06:37:19341 PerformAction("AddObject", ObjectPath("/org/chromium/SecondObject"));
[email protected]9cc40cb2013-03-25 18:20:08342 WaitForObject();
343
[email protected]2a57ca642013-06-13 06:37:19344 std::vector<ObjectPath> object_paths = object_manager_->GetObjects();
[email protected]9cc40cb2013-03-25 18:20:08345 ASSERT_EQ(2U, object_paths.size());
346
[email protected]2a57ca642013-06-13 06:37:19347 PerformAction("RemoveObject", ObjectPath("/org/chromium/SecondObject"));
[email protected]9cc40cb2013-03-25 18:20:08348 WaitForRemoveObject();
349
[email protected]2a57ca642013-06-13 06:37:19350 ObjectProxy* object_proxy = object_manager_->GetObjectProxy(
351 ObjectPath("/org/chromium/SecondObject"));
Ben Chan14d50032017-11-09 20:20:16352 EXPECT_EQ(nullptr, object_proxy);
[email protected]9cc40cb2013-03-25 18:20:08353
354 Properties* properties = static_cast<Properties*>(
[email protected]2a57ca642013-06-13 06:37:19355 object_manager_->GetProperties(ObjectPath("/org/chromium/SecondObject"),
356 "org.chromium.TestInterface"));
Ben Chan14d50032017-11-09 20:20:16357 EXPECT_EQ(nullptr, properties);
[email protected]9cc40cb2013-03-25 18:20:08358
359 object_paths = object_manager_->GetObjects();
360 ASSERT_EQ(1U, object_paths.size());
[email protected]2a57ca642013-06-13 06:37:19361 EXPECT_EQ(ObjectPath("/org/chromium/TestObject"), object_paths[0]);
[email protected]9cc40cb2013-03-25 18:20:08362
363 object_paths =
364 object_manager_->GetObjectsWithInterface("org.chromium.TestInterface");
365 ASSERT_EQ(1U, object_paths.size());
[email protected]2a57ca642013-06-13 06:37:19366 EXPECT_EQ(ObjectPath("/org/chromium/TestObject"), object_paths[0]);
[email protected]9cc40cb2013-03-25 18:20:08367}
[email protected]2a57ca642013-06-13 06:37:19368
[email protected]043fb8c2014-03-07 02:24:33369TEST_F(ObjectManagerTest, OwnershipLost) {
370 PerformAction("ReleaseOwnership", ObjectPath("/org/chromium/TestService"));
371 WaitForRemoveObject();
372
373 std::vector<ObjectPath> object_paths = object_manager_->GetObjects();
374 ASSERT_EQ(0U, object_paths.size());
375}
376
377TEST_F(ObjectManagerTest, OwnershipLostAndRegained) {
378 PerformAction("Ownership", ObjectPath("/org/chromium/TestService"));
379 WaitForRemoveObject();
380 WaitForObject();
381
382 std::vector<ObjectPath> object_paths = object_manager_->GetObjects();
383 ASSERT_EQ(1U, object_paths.size());
384}
385
armansitoebff093d2014-09-05 17:49:34386TEST_F(ObjectManagerTest, PropertiesChangedAsObjectsReceived) {
387 // Remove the existing object manager.
388 object_manager_->UnregisterInterface("org.chromium.TestInterface");
389 run_loop_.reset(new base::RunLoop);
390 EXPECT_TRUE(bus_->RemoveObjectManager(
hashimoto067d84f522016-01-05 08:48:03391 test_service_->service_name(),
armansitoebff093d2014-09-05 17:49:34392 ObjectPath("/org/chromium/TestService"),
393 run_loop_->QuitClosure()));
394 run_loop_->Run();
395
396 PerformAction("SetSendImmediatePropertiesChanged",
397 ObjectPath("/org/chromium/TestService"));
398
399 object_manager_ = bus_->GetObjectManager(
hashimoto067d84f522016-01-05 08:48:03400 test_service_->service_name(),
armansitoebff093d2014-09-05 17:49:34401 ObjectPath("/org/chromium/TestService"));
402 object_manager_->RegisterInterface("org.chromium.TestInterface", this);
403
404 // The newly created object manager should call GetManagedObjects immediately
405 // after setting up the match rule for PropertiesChanged. We should process
406 // the PropertiesChanged event right after that. If we don't receive it within
407 // 2 seconds, then fail the test.
Gabriel Charette694c3c332019-08-19 14:53:05408 task_environment_.GetMainThreadTaskRunner()->PostDelayedTask(
kylechar39c39282019-02-19 19:04:04409 FROM_HERE,
410 base::BindOnce(&ObjectManagerTest::PropertiesChangedTestTimeout,
411 base::Unretained(this)),
armansitoebff093d2014-09-05 17:49:34412 base::TimeDelta::FromSeconds(2));
413
414 while (last_name_value_ != "ChangedTestServiceName" && !timeout_expired_) {
415 run_loop_.reset(new base::RunLoop);
416 run_loop_->Run();
417 }
418}
419
[email protected]2a57ca642013-06-13 06:37:19420} // namespace dbus