blob: 6329aea6f1edf833e3ddbed96594e50fffb505c4 [file] [log] [blame]
Avi Drissmanf75e37f2022-09-13 19:40:311// Copyright 2013 The Chromium Authors
[email protected]9cc40cb2013-03-25 18:20:082// 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
Peter Boström6b701822021-04-15 03:53:0810#include <memory>
[email protected]9cc40cb2013-03-25 18:20:0811#include <string>
12#include <vector>
13
[email protected]9cc40cb2013-03-25 18:20:0814#include "base/bind.h"
Keishi Hattorif28f4f82022-06-21 11:32:1515#include "base/memory/raw_ptr.h"
Carlos Caballerodd8bf7b042019-07-30 14:14:1516#include "base/message_loop/message_pump_type.h"
earthdok9562caf2014-09-03 10:32:3617#include "base/run_loop.h"
Patrick Monette643cdf62021-10-15 19:13:4218#include "base/task/single_thread_task_runner.h"
Gabriel Charettec7108742019-08-23 03:31:4019#include "base/test/task_environment.h"
[email protected]9cc40cb2013-03-25 18:20:0820#include "base/threading/thread.h"
21#include "base/threading/thread_restrictions.h"
Gabriel Charetted87f10f2022-03-31 00:44:2222#include "base/time/time.h"
[email protected]9cc40cb2013-03-25 18:20:0823#include "dbus/bus.h"
24#include "dbus/object_path.h"
25#include "dbus/object_proxy.h"
26#include "dbus/property.h"
27#include "dbus/test_service.h"
28#include "testing/gtest/include/gtest/gtest.h"
Gabriel Charettead330422021-07-21 00:49:2829#include "third_party/abseil-cpp/absl/types/optional.h"
[email protected]9cc40cb2013-03-25 18:20:0830
[email protected]2a57ca642013-06-13 06:37:1931namespace dbus {
32
[email protected]9cc40cb2013-03-25 18:20:0833// The object manager test exercises the asynchronous APIs in ObjectManager,
34// and by extension PropertySet and Property<>.
35class ObjectManagerTest
36 : public testing::Test,
[email protected]2a57ca642013-06-13 06:37:1937 public ObjectManager::Interface {
[email protected]9cc40cb2013-03-25 18:20:0838 public:
armansitoebff093d2014-09-05 17:49:3439 ObjectManagerTest() : timeout_expired_(false) {
[email protected]9cc40cb2013-03-25 18:20:0840 }
41
[email protected]2a57ca642013-06-13 06:37:1942 struct Properties : public PropertySet {
43 Property<std::string> name;
avi22437c692015-12-22 18:12:4544 Property<int16_t> version;
Ben Chanc7c9c762017-11-08 01:50:2145 Property<std::vector<std::string>> methods;
46 Property<std::vector<ObjectPath>> objects;
[email protected]9cc40cb2013-03-25 18:20:0847
[email protected]2a57ca642013-06-13 06:37:1948 Properties(ObjectProxy* object_proxy,
[email protected]9cc40cb2013-03-25 18:20:0849 const std::string& interface_name,
50 PropertyChangedCallback property_changed_callback)
[email protected]2a57ca642013-06-13 06:37:1951 : PropertySet(object_proxy, interface_name, property_changed_callback) {
[email protected]9cc40cb2013-03-25 18:20:0852 RegisterProperty("Name", &name);
53 RegisterProperty("Version", &version);
54 RegisterProperty("Methods", &methods);
55 RegisterProperty("Objects", &objects);
56 }
57 };
58
dcheng3bb7119c2014-12-29 18:30:1759 PropertySet* CreateProperties(ObjectProxy* object_proxy,
60 const ObjectPath& object_path,
61 const std::string& interface_name) override {
[email protected]9cc40cb2013-03-25 18:20:0862 Properties* properties = new Properties(
63 object_proxy, interface_name,
Reilly Grantd4e66132019-11-22 17:14:5064 base::BindRepeating(&ObjectManagerTest::OnPropertyChanged,
65 base::Unretained(this), object_path));
[email protected]2a57ca642013-06-13 06:37:1966 return static_cast<PropertySet*>(properties);
[email protected]9cc40cb2013-03-25 18:20:0867 }
68
dcheng3bb7119c2014-12-29 18:30:1769 void SetUp() override {
[email protected]9cc40cb2013-03-25 18:20:0870 // Make the main thread not to allow IO.
Gabriel Charettead330422021-07-21 00:49:2871 disallow_blocking_.emplace();
[email protected]9cc40cb2013-03-25 18:20:0872
73 // Start the D-Bus thread.
Peter Boström6b701822021-04-15 03:53:0874 dbus_thread_ = std::make_unique<base::Thread>("D-Bus Thread");
[email protected]9cc40cb2013-03-25 18:20:0875 base::Thread::Options thread_options;
Carlos Caballerodd8bf7b042019-07-30 14:14:1576 thread_options.message_pump_type = base::MessagePumpType::IO;
Olivier Li90cd9842021-05-12 02:55:0677 ASSERT_TRUE(dbus_thread_->StartWithOptions(std::move(thread_options)));
[email protected]9cc40cb2013-03-25 18:20:0878
79 // Start the test service, using the D-Bus thread.
[email protected]2a57ca642013-06-13 06:37:1980 TestService::Options options;
skyostil8a033aa2015-06-17 15:46:0481 options.dbus_task_runner = dbus_thread_->task_runner();
Peter Boström6b701822021-04-15 03:53:0882 test_service_ = std::make_unique<TestService>(options);
[email protected]9cc40cb2013-03-25 18:20:0883 ASSERT_TRUE(test_service_->StartService());
Ryo Hashimoto3bbeb5c2018-08-13 04:58:3984 test_service_->WaitUntilServiceIsStarted();
[email protected]9cc40cb2013-03-25 18:20:0885 ASSERT_TRUE(test_service_->HasDBusThread());
86
87 // Create the client, using the D-Bus thread.
[email protected]2a57ca642013-06-13 06:37:1988 Bus::Options bus_options;
89 bus_options.bus_type = Bus::SESSION;
90 bus_options.connection_type = Bus::PRIVATE;
skyostil8a033aa2015-06-17 15:46:0491 bus_options.dbus_task_runner = dbus_thread_->task_runner();
[email protected]2a57ca642013-06-13 06:37:1992 bus_ = new Bus(bus_options);
[email protected]9cc40cb2013-03-25 18:20:0893 ASSERT_TRUE(bus_->HasDBusThread());
94
95 object_manager_ = bus_->GetObjectManager(
hashimoto067d84f522016-01-05 08:48:0396 test_service_->service_name(),
[email protected]2a57ca642013-06-13 06:37:1997 ObjectPath("/org/chromium/TestService"));
[email protected]9cc40cb2013-03-25 18:20:0898 object_manager_->RegisterInterface("org.chromium.TestInterface", this);
99
[email protected]9cc40cb2013-03-25 18:20:08100 WaitForObject();
101 }
102
dcheng3bb7119c2014-12-29 18:30:17103 void TearDown() override {
[email protected]9cc40cb2013-03-25 18:20:08104 bus_->ShutdownOnDBusThreadAndBlock();
105
106 // Shut down the service.
107 test_service_->ShutdownAndBlock();
108
[email protected]9cc40cb2013-03-25 18:20:08109 // Stopping a thread is considered an IO operation, so do this after
110 // allowing IO.
Gabriel Charettead330422021-07-21 00:49:28111 disallow_blocking_.reset();
[email protected]9cc40cb2013-03-25 18:20:08112 test_service_->Stop();
earthdok9562caf2014-09-03 10:32:36113
114 base::RunLoop().RunUntilIdle();
[email protected]9cc40cb2013-03-25 18:20:08115 }
116
[email protected]2a57ca642013-06-13 06:37:19117 void MethodCallback(Response* response) {
[email protected]9cc40cb2013-03-25 18:20:08118 method_callback_called_ = true;
earthdok9562caf2014-09-03 10:32:36119 run_loop_->Quit();
[email protected]9cc40cb2013-03-25 18:20:08120 }
121
armansitoebff093d2014-09-05 17:49:34122 // Called from the PropertiesChangedAsObjectsReceived test case. The test will
123 // not run the message loop if it receives the expected PropertiesChanged
124 // signal before the timeout. This method immediately fails the test.
125 void PropertiesChangedTestTimeout() {
126 timeout_expired_ = true;
127 run_loop_->Quit();
128
129 FAIL() << "Never received PropertiesChanged";
130 }
131
[email protected]2a57ca642013-06-13 06:37:19132 protected:
[email protected]9cc40cb2013-03-25 18:20:08133 // Called when an object is added.
dcheng3bb7119c2014-12-29 18:30:17134 void ObjectAdded(const ObjectPath& object_path,
135 const std::string& interface_name) override {
[email protected]9cc40cb2013-03-25 18:20:08136 added_objects_.push_back(std::make_pair(object_path, interface_name));
earthdok9562caf2014-09-03 10:32:36137 run_loop_->Quit();
[email protected]9cc40cb2013-03-25 18:20:08138 }
139
140 // Called when an object is removed.
dcheng3bb7119c2014-12-29 18:30:17141 void ObjectRemoved(const ObjectPath& object_path,
142 const std::string& interface_name) override {
[email protected]9cc40cb2013-03-25 18:20:08143 removed_objects_.push_back(std::make_pair(object_path, interface_name));
earthdok9562caf2014-09-03 10:32:36144 run_loop_->Quit();
[email protected]9cc40cb2013-03-25 18:20:08145 }
146
147 // Called when a property value is updated.
[email protected]2a57ca642013-06-13 06:37:19148 void OnPropertyChanged(const ObjectPath& object_path,
[email protected]9cc40cb2013-03-25 18:20:08149 const std::string& name) {
armansitoebff093d2014-09-05 17:49:34150 // Store the value of the "Name" property if that's the one that
151 // changed.
152 Properties* properties = static_cast<Properties*>(
153 object_manager_->GetProperties(
154 object_path,
155 "org.chromium.TestInterface"));
156 if (name == properties->name.name())
157 last_name_value_ = properties->name.value();
158
159 // Store the updated property.
[email protected]9cc40cb2013-03-25 18:20:08160 updated_properties_.push_back(name);
earthdok9562caf2014-09-03 10:32:36161 run_loop_->Quit();
[email protected]9cc40cb2013-03-25 18:20:08162 }
163
164 static const size_t kExpectedObjects = 1;
165 static const size_t kExpectedProperties = 4;
166
167 void WaitForObject() {
168 while (added_objects_.size() < kExpectedObjects ||
earthdok9562caf2014-09-03 10:32:36169 updated_properties_.size() < kExpectedProperties) {
Peter Boström6b701822021-04-15 03:53:08170 run_loop_ = std::make_unique<base::RunLoop>();
earthdok9562caf2014-09-03 10:32:36171 run_loop_->Run();
172 }
[email protected]9cc40cb2013-03-25 18:20:08173 for (size_t i = 0; i < kExpectedObjects; ++i)
174 added_objects_.erase(added_objects_.begin());
175 for (size_t i = 0; i < kExpectedProperties; ++i)
176 updated_properties_.erase(updated_properties_.begin());
177 }
178
179 void WaitForRemoveObject() {
earthdok9562caf2014-09-03 10:32:36180 while (removed_objects_.size() < kExpectedObjects) {
Peter Boström6b701822021-04-15 03:53:08181 run_loop_ = std::make_unique<base::RunLoop>();
earthdok9562caf2014-09-03 10:32:36182 run_loop_->Run();
183 }
[email protected]9cc40cb2013-03-25 18:20:08184 for (size_t i = 0; i < kExpectedObjects; ++i)
185 removed_objects_.erase(removed_objects_.begin());
186 }
187
188 void WaitForMethodCallback() {
Peter Boström6b701822021-04-15 03:53:08189 run_loop_ = std::make_unique<base::RunLoop>();
earthdok9562caf2014-09-03 10:32:36190 run_loop_->Run();
[email protected]9cc40cb2013-03-25 18:20:08191 method_callback_called_ = false;
192 }
193
[email protected]2a57ca642013-06-13 06:37:19194 void PerformAction(const std::string& action, const ObjectPath& object_path) {
195 ObjectProxy* object_proxy = bus_->GetObjectProxy(
hashimoto067d84f522016-01-05 08:48:03196 test_service_->service_name(),
[email protected]2a57ca642013-06-13 06:37:19197 ObjectPath("/org/chromium/TestObject"));
[email protected]9cc40cb2013-03-25 18:20:08198
[email protected]2a57ca642013-06-13 06:37:19199 MethodCall method_call("org.chromium.TestInterface", "PerformAction");
200 MessageWriter writer(&method_call);
[email protected]9cc40cb2013-03-25 18:20:08201 writer.AppendString(action);
202 writer.AppendObjectPath(object_path);
203
Reilly Grantd4e66132019-11-22 17:14:50204 object_proxy->CallMethod(&method_call, ObjectProxy::TIMEOUT_USE_DEFAULT,
205 base::BindOnce(&ObjectManagerTest::MethodCallback,
206 base::Unretained(this)));
[email protected]9cc40cb2013-03-25 18:20:08207 WaitForMethodCallback();
208 }
209
Gabriel Charette1858a232019-09-09 07:50:49210 base::test::SingleThreadTaskEnvironment task_environment_;
Gabriel Charettead330422021-07-21 00:49:28211 absl::optional<base::ScopedDisallowBlocking> disallow_blocking_;
dcheng2a193282016-04-08 22:55:04212 std::unique_ptr<base::RunLoop> run_loop_;
213 std::unique_ptr<base::Thread> dbus_thread_;
[email protected]2a57ca642013-06-13 06:37:19214 scoped_refptr<Bus> bus_;
Keishi Hattorif28f4f82022-06-21 11:32:15215 raw_ptr<ObjectManager> object_manager_;
dcheng2a193282016-04-08 22:55:04216 std::unique_ptr<TestService> test_service_;
[email protected]9cc40cb2013-03-25 18:20:08217
armansitoebff093d2014-09-05 17:49:34218 std::string last_name_value_;
219 bool timeout_expired_;
220
Ben Chanc7c9c762017-11-08 01:50:21221 std::vector<std::pair<ObjectPath, std::string>> added_objects_;
222 std::vector<std::pair<ObjectPath, std::string>> removed_objects_;
[email protected]9cc40cb2013-03-25 18:20:08223 std::vector<std::string> updated_properties_;
224
225 bool method_callback_called_;
226};
227
228
229TEST_F(ObjectManagerTest, InitialObject) {
[email protected]2a57ca642013-06-13 06:37:19230 ObjectProxy* object_proxy = object_manager_->GetObjectProxy(
231 ObjectPath("/org/chromium/TestObject"));
Ben Chan14d50032017-11-09 20:20:16232 EXPECT_NE(nullptr, object_proxy);
[email protected]9cc40cb2013-03-25 18:20:08233
234 Properties* properties = static_cast<Properties*>(
[email protected]2a57ca642013-06-13 06:37:19235 object_manager_->GetProperties(ObjectPath("/org/chromium/TestObject"),
236 "org.chromium.TestInterface"));
Ben Chan14d50032017-11-09 20:20:16237 EXPECT_NE(nullptr, properties);
[email protected]9cc40cb2013-03-25 18:20:08238
239 EXPECT_EQ("TestService", properties->name.value());
240 EXPECT_EQ(10, properties->version.value());
241
242 std::vector<std::string> methods = properties->methods.value();
243 ASSERT_EQ(4U, methods.size());
244 EXPECT_EQ("Echo", methods[0]);
245 EXPECT_EQ("SlowEcho", methods[1]);
246 EXPECT_EQ("AsyncEcho", methods[2]);
247 EXPECT_EQ("BrokenMethod", methods[3]);
248
[email protected]2a57ca642013-06-13 06:37:19249 std::vector<ObjectPath> objects = properties->objects.value();
[email protected]9cc40cb2013-03-25 18:20:08250 ASSERT_EQ(1U, objects.size());
[email protected]2a57ca642013-06-13 06:37:19251 EXPECT_EQ(ObjectPath("/TestObjectPath"), objects[0]);
[email protected]9cc40cb2013-03-25 18:20:08252}
253
254TEST_F(ObjectManagerTest, UnknownObjectProxy) {
[email protected]2a57ca642013-06-13 06:37:19255 ObjectProxy* object_proxy = object_manager_->GetObjectProxy(
256 ObjectPath("/org/chromium/UnknownObject"));
Ben Chan14d50032017-11-09 20:20:16257 EXPECT_EQ(nullptr, object_proxy);
[email protected]9cc40cb2013-03-25 18:20:08258}
259
260TEST_F(ObjectManagerTest, UnknownObjectProperties) {
261 Properties* properties = static_cast<Properties*>(
[email protected]2a57ca642013-06-13 06:37:19262 object_manager_->GetProperties(ObjectPath("/org/chromium/UnknownObject"),
263 "org.chromium.TestInterface"));
Ben Chan14d50032017-11-09 20:20:16264 EXPECT_EQ(nullptr, properties);
[email protected]9cc40cb2013-03-25 18:20:08265}
266
267TEST_F(ObjectManagerTest, UnknownInterfaceProperties) {
268 Properties* properties = static_cast<Properties*>(
[email protected]2a57ca642013-06-13 06:37:19269 object_manager_->GetProperties(ObjectPath("/org/chromium/TestObject"),
270 "org.chromium.UnknownService"));
Ben Chan14d50032017-11-09 20:20:16271 EXPECT_EQ(nullptr, properties);
[email protected]9cc40cb2013-03-25 18:20:08272}
273
274TEST_F(ObjectManagerTest, GetObjects) {
[email protected]2a57ca642013-06-13 06:37:19275 std::vector<ObjectPath> object_paths = object_manager_->GetObjects();
[email protected]9cc40cb2013-03-25 18:20:08276 ASSERT_EQ(1U, object_paths.size());
[email protected]2a57ca642013-06-13 06:37:19277 EXPECT_EQ(ObjectPath("/org/chromium/TestObject"), object_paths[0]);
[email protected]9cc40cb2013-03-25 18:20:08278}
279
280TEST_F(ObjectManagerTest, GetObjectsWithInterface) {
[email protected]2a57ca642013-06-13 06:37:19281 std::vector<ObjectPath> object_paths =
[email protected]9cc40cb2013-03-25 18:20:08282 object_manager_->GetObjectsWithInterface("org.chromium.TestInterface");
283 ASSERT_EQ(1U, object_paths.size());
[email protected]2a57ca642013-06-13 06:37:19284 EXPECT_EQ(ObjectPath("/org/chromium/TestObject"), object_paths[0]);
[email protected]9cc40cb2013-03-25 18:20:08285}
286
287TEST_F(ObjectManagerTest, GetObjectsWithUnknownInterface) {
[email protected]2a57ca642013-06-13 06:37:19288 std::vector<ObjectPath> object_paths =
[email protected]9cc40cb2013-03-25 18:20:08289 object_manager_->GetObjectsWithInterface("org.chromium.UnknownService");
290 EXPECT_EQ(0U, object_paths.size());
291}
292
293TEST_F(ObjectManagerTest, SameObject) {
[email protected]2a57ca642013-06-13 06:37:19294 ObjectManager* object_manager = bus_->GetObjectManager(
hashimoto067d84f522016-01-05 08:48:03295 test_service_->service_name(),
[email protected]2a57ca642013-06-13 06:37:19296 ObjectPath("/org/chromium/TestService"));
[email protected]9cc40cb2013-03-25 18:20:08297 EXPECT_EQ(object_manager_, object_manager);
298}
299
300TEST_F(ObjectManagerTest, DifferentObjectForService) {
[email protected]2a57ca642013-06-13 06:37:19301 ObjectManager* object_manager = bus_->GetObjectManager(
[email protected]9cc40cb2013-03-25 18:20:08302 "org.chromium.DifferentService",
[email protected]2a57ca642013-06-13 06:37:19303 ObjectPath("/org/chromium/TestService"));
[email protected]9cc40cb2013-03-25 18:20:08304 EXPECT_NE(object_manager_, object_manager);
305}
306
307TEST_F(ObjectManagerTest, DifferentObjectForPath) {
[email protected]2a57ca642013-06-13 06:37:19308 ObjectManager* object_manager = bus_->GetObjectManager(
hashimoto067d84f522016-01-05 08:48:03309 test_service_->service_name(),
[email protected]2a57ca642013-06-13 06:37:19310 ObjectPath("/org/chromium/DifferentService"));
[email protected]9cc40cb2013-03-25 18:20:08311 EXPECT_NE(object_manager_, object_manager);
312}
313
314TEST_F(ObjectManagerTest, SecondObject) {
[email protected]2a57ca642013-06-13 06:37:19315 PerformAction("AddObject", ObjectPath("/org/chromium/SecondObject"));
[email protected]9cc40cb2013-03-25 18:20:08316 WaitForObject();
317
[email protected]2a57ca642013-06-13 06:37:19318 ObjectProxy* object_proxy = object_manager_->GetObjectProxy(
319 ObjectPath("/org/chromium/SecondObject"));
Ben Chan14d50032017-11-09 20:20:16320 EXPECT_NE(nullptr, object_proxy);
[email protected]9cc40cb2013-03-25 18:20:08321
322 Properties* properties = static_cast<Properties*>(
[email protected]2a57ca642013-06-13 06:37:19323 object_manager_->GetProperties(ObjectPath("/org/chromium/SecondObject"),
324 "org.chromium.TestInterface"));
Ben Chan14d50032017-11-09 20:20:16325 EXPECT_NE(nullptr, properties);
[email protected]9cc40cb2013-03-25 18:20:08326
[email protected]2a57ca642013-06-13 06:37:19327 std::vector<ObjectPath> object_paths = object_manager_->GetObjects();
[email protected]9cc40cb2013-03-25 18:20:08328 ASSERT_EQ(2U, object_paths.size());
329
330 std::sort(object_paths.begin(), object_paths.end());
[email protected]2a57ca642013-06-13 06:37:19331 EXPECT_EQ(ObjectPath("/org/chromium/SecondObject"), object_paths[0]);
332 EXPECT_EQ(ObjectPath("/org/chromium/TestObject"), object_paths[1]);
[email protected]9cc40cb2013-03-25 18:20:08333
334 object_paths =
335 object_manager_->GetObjectsWithInterface("org.chromium.TestInterface");
336 ASSERT_EQ(2U, object_paths.size());
337
338 std::sort(object_paths.begin(), object_paths.end());
[email protected]2a57ca642013-06-13 06:37:19339 EXPECT_EQ(ObjectPath("/org/chromium/SecondObject"), object_paths[0]);
340 EXPECT_EQ(ObjectPath("/org/chromium/TestObject"), object_paths[1]);
[email protected]9cc40cb2013-03-25 18:20:08341}
342
343TEST_F(ObjectManagerTest, RemoveSecondObject) {
[email protected]2a57ca642013-06-13 06:37:19344 PerformAction("AddObject", ObjectPath("/org/chromium/SecondObject"));
[email protected]9cc40cb2013-03-25 18:20:08345 WaitForObject();
346
[email protected]2a57ca642013-06-13 06:37:19347 std::vector<ObjectPath> object_paths = object_manager_->GetObjects();
[email protected]9cc40cb2013-03-25 18:20:08348 ASSERT_EQ(2U, object_paths.size());
349
[email protected]2a57ca642013-06-13 06:37:19350 PerformAction("RemoveObject", ObjectPath("/org/chromium/SecondObject"));
[email protected]9cc40cb2013-03-25 18:20:08351 WaitForRemoveObject();
352
[email protected]2a57ca642013-06-13 06:37:19353 ObjectProxy* object_proxy = object_manager_->GetObjectProxy(
354 ObjectPath("/org/chromium/SecondObject"));
Ben Chan14d50032017-11-09 20:20:16355 EXPECT_EQ(nullptr, object_proxy);
[email protected]9cc40cb2013-03-25 18:20:08356
357 Properties* properties = static_cast<Properties*>(
[email protected]2a57ca642013-06-13 06:37:19358 object_manager_->GetProperties(ObjectPath("/org/chromium/SecondObject"),
359 "org.chromium.TestInterface"));
Ben Chan14d50032017-11-09 20:20:16360 EXPECT_EQ(nullptr, properties);
[email protected]9cc40cb2013-03-25 18:20:08361
362 object_paths = object_manager_->GetObjects();
363 ASSERT_EQ(1U, object_paths.size());
[email protected]2a57ca642013-06-13 06:37:19364 EXPECT_EQ(ObjectPath("/org/chromium/TestObject"), object_paths[0]);
[email protected]9cc40cb2013-03-25 18:20:08365
366 object_paths =
367 object_manager_->GetObjectsWithInterface("org.chromium.TestInterface");
368 ASSERT_EQ(1U, object_paths.size());
[email protected]2a57ca642013-06-13 06:37:19369 EXPECT_EQ(ObjectPath("/org/chromium/TestObject"), object_paths[0]);
[email protected]9cc40cb2013-03-25 18:20:08370}
[email protected]2a57ca642013-06-13 06:37:19371
[email protected]043fb8c2014-03-07 02:24:33372TEST_F(ObjectManagerTest, OwnershipLost) {
373 PerformAction("ReleaseOwnership", ObjectPath("/org/chromium/TestService"));
374 WaitForRemoveObject();
375
376 std::vector<ObjectPath> object_paths = object_manager_->GetObjects();
377 ASSERT_EQ(0U, object_paths.size());
378}
379
380TEST_F(ObjectManagerTest, OwnershipLostAndRegained) {
381 PerformAction("Ownership", ObjectPath("/org/chromium/TestService"));
382 WaitForRemoveObject();
383 WaitForObject();
384
385 std::vector<ObjectPath> object_paths = object_manager_->GetObjects();
386 ASSERT_EQ(1U, object_paths.size());
387}
388
Anders Hartvoll Ruudd7c7a3c2021-02-05 08:26:37389// Flaky: crbug.com/1174515
390TEST_F(ObjectManagerTest, DISABLED_PropertiesChangedAsObjectsReceived) {
armansitoebff093d2014-09-05 17:49:34391 // Remove the existing object manager.
392 object_manager_->UnregisterInterface("org.chromium.TestInterface");
Peter Boström6b701822021-04-15 03:53:08393 run_loop_ = std::make_unique<base::RunLoop>();
armansitoebff093d2014-09-05 17:49:34394 EXPECT_TRUE(bus_->RemoveObjectManager(
hashimoto067d84f522016-01-05 08:48:03395 test_service_->service_name(),
armansitoebff093d2014-09-05 17:49:34396 ObjectPath("/org/chromium/TestService"),
397 run_loop_->QuitClosure()));
398 run_loop_->Run();
399
400 PerformAction("SetSendImmediatePropertiesChanged",
401 ObjectPath("/org/chromium/TestService"));
402
403 object_manager_ = bus_->GetObjectManager(
hashimoto067d84f522016-01-05 08:48:03404 test_service_->service_name(),
armansitoebff093d2014-09-05 17:49:34405 ObjectPath("/org/chromium/TestService"));
406 object_manager_->RegisterInterface("org.chromium.TestInterface", this);
407
408 // The newly created object manager should call GetManagedObjects immediately
409 // after setting up the match rule for PropertiesChanged. We should process
410 // the PropertiesChanged event right after that. If we don't receive it within
411 // 2 seconds, then fail the test.
Gabriel Charette694c3c332019-08-19 14:53:05412 task_environment_.GetMainThreadTaskRunner()->PostDelayedTask(
kylechar39c39282019-02-19 19:04:04413 FROM_HERE,
414 base::BindOnce(&ObjectManagerTest::PropertiesChangedTestTimeout,
415 base::Unretained(this)),
Peter Kastinge5a38ed2021-10-02 03:06:35416 base::Seconds(2));
armansitoebff093d2014-09-05 17:49:34417
418 while (last_name_value_ != "ChangedTestServiceName" && !timeout_expired_) {
Peter Boström6b701822021-04-15 03:53:08419 run_loop_ = std::make_unique<base::RunLoop>();
armansitoebff093d2014-09-05 17:49:34420 run_loop_->Run();
421 }
422}
423
[email protected]2a57ca642013-06-13 06:37:19424} // namespace dbus