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

Side by Side Diff: dbus/object_manager_unittest.cc

Issue 1559873005: dbus: Use randomly generated string as a TestService's service name (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 unified diff | Download patch
« no previous file with comments | « dbus/end_to_end_sync_unittest.cc ('k') | dbus/object_proxy_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "dbus/object_manager.h" 5 #include "dbus/object_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 80
81 // Create the client, using the D-Bus thread. 81 // Create the client, using the D-Bus thread.
82 Bus::Options bus_options; 82 Bus::Options bus_options;
83 bus_options.bus_type = Bus::SESSION; 83 bus_options.bus_type = Bus::SESSION;
84 bus_options.connection_type = Bus::PRIVATE; 84 bus_options.connection_type = Bus::PRIVATE;
85 bus_options.dbus_task_runner = dbus_thread_->task_runner(); 85 bus_options.dbus_task_runner = dbus_thread_->task_runner();
86 bus_ = new Bus(bus_options); 86 bus_ = new Bus(bus_options);
87 ASSERT_TRUE(bus_->HasDBusThread()); 87 ASSERT_TRUE(bus_->HasDBusThread());
88 88
89 object_manager_ = bus_->GetObjectManager( 89 object_manager_ = bus_->GetObjectManager(
90 "org.chromium.TestService", 90 test_service_->service_name(),
91 ObjectPath("/org/chromium/TestService")); 91 ObjectPath("/org/chromium/TestService"));
92 object_manager_->RegisterInterface("org.chromium.TestInterface", this); 92 object_manager_->RegisterInterface("org.chromium.TestInterface", this);
93 93
94 WaitForObject(); 94 WaitForObject();
95 } 95 }
96 96
97 void TearDown() override { 97 void TearDown() override {
98 bus_->ShutdownOnDBusThreadAndBlock(); 98 bus_->ShutdownOnDBusThreadAndBlock();
99 99
100 // Shut down the service. 100 // Shut down the service.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 182 }
183 183
184 void WaitForMethodCallback() { 184 void WaitForMethodCallback() {
185 run_loop_.reset(new base::RunLoop); 185 run_loop_.reset(new base::RunLoop);
186 run_loop_->Run(); 186 run_loop_->Run();
187 method_callback_called_ = false; 187 method_callback_called_ = false;
188 } 188 }
189 189
190 void PerformAction(const std::string& action, const ObjectPath& object_path) { 190 void PerformAction(const std::string& action, const ObjectPath& object_path) {
191 ObjectProxy* object_proxy = bus_->GetObjectProxy( 191 ObjectProxy* object_proxy = bus_->GetObjectProxy(
192 "org.chromium.TestService", 192 test_service_->service_name(),
193 ObjectPath("/org/chromium/TestObject")); 193 ObjectPath("/org/chromium/TestObject"));
194 194
195 MethodCall method_call("org.chromium.TestInterface", "PerformAction"); 195 MethodCall method_call("org.chromium.TestInterface", "PerformAction");
196 MessageWriter writer(&method_call); 196 MessageWriter writer(&method_call);
197 writer.AppendString(action); 197 writer.AppendString(action);
198 writer.AppendObjectPath(object_path); 198 writer.AppendObjectPath(object_path);
199 199
200 object_proxy->CallMethod(&method_call, 200 object_proxy->CallMethod(&method_call,
201 ObjectProxy::TIMEOUT_USE_DEFAULT, 201 ObjectProxy::TIMEOUT_USE_DEFAULT,
202 base::Bind(&ObjectManagerTest::MethodCallback, 202 base::Bind(&ObjectManagerTest::MethodCallback,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 } 281 }
282 282
283 TEST_F(ObjectManagerTest, GetObjectsWithUnknownInterface) { 283 TEST_F(ObjectManagerTest, GetObjectsWithUnknownInterface) {
284 std::vector<ObjectPath> object_paths = 284 std::vector<ObjectPath> object_paths =
285 object_manager_->GetObjectsWithInterface("org.chromium.UnknownService"); 285 object_manager_->GetObjectsWithInterface("org.chromium.UnknownService");
286 EXPECT_EQ(0U, object_paths.size()); 286 EXPECT_EQ(0U, object_paths.size());
287 } 287 }
288 288
289 TEST_F(ObjectManagerTest, SameObject) { 289 TEST_F(ObjectManagerTest, SameObject) {
290 ObjectManager* object_manager = bus_->GetObjectManager( 290 ObjectManager* object_manager = bus_->GetObjectManager(
291 "org.chromium.TestService", 291 test_service_->service_name(),
292 ObjectPath("/org/chromium/TestService")); 292 ObjectPath("/org/chromium/TestService"));
293 EXPECT_EQ(object_manager_, object_manager); 293 EXPECT_EQ(object_manager_, object_manager);
294 } 294 }
295 295
296 TEST_F(ObjectManagerTest, DifferentObjectForService) { 296 TEST_F(ObjectManagerTest, DifferentObjectForService) {
297 ObjectManager* object_manager = bus_->GetObjectManager( 297 ObjectManager* object_manager = bus_->GetObjectManager(
298 "org.chromium.DifferentService", 298 "org.chromium.DifferentService",
299 ObjectPath("/org/chromium/TestService")); 299 ObjectPath("/org/chromium/TestService"));
300 EXPECT_NE(object_manager_, object_manager); 300 EXPECT_NE(object_manager_, object_manager);
301 } 301 }
302 302
303 TEST_F(ObjectManagerTest, DifferentObjectForPath) { 303 TEST_F(ObjectManagerTest, DifferentObjectForPath) {
304 ObjectManager* object_manager = bus_->GetObjectManager( 304 ObjectManager* object_manager = bus_->GetObjectManager(
305 "org.chromium.TestService", 305 test_service_->service_name(),
306 ObjectPath("/org/chromium/DifferentService")); 306 ObjectPath("/org/chromium/DifferentService"));
307 EXPECT_NE(object_manager_, object_manager); 307 EXPECT_NE(object_manager_, object_manager);
308 } 308 }
309 309
310 TEST_F(ObjectManagerTest, SecondObject) { 310 TEST_F(ObjectManagerTest, SecondObject) {
311 PerformAction("AddObject", ObjectPath("/org/chromium/SecondObject")); 311 PerformAction("AddObject", ObjectPath("/org/chromium/SecondObject"));
312 WaitForObject(); 312 WaitForObject();
313 313
314 ObjectProxy* object_proxy = object_manager_->GetObjectProxy( 314 ObjectProxy* object_proxy = object_manager_->GetObjectProxy(
315 ObjectPath("/org/chromium/SecondObject")); 315 ObjectPath("/org/chromium/SecondObject"));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 380
381 std::vector<ObjectPath> object_paths = object_manager_->GetObjects(); 381 std::vector<ObjectPath> object_paths = object_manager_->GetObjects();
382 ASSERT_EQ(1U, object_paths.size()); 382 ASSERT_EQ(1U, object_paths.size());
383 } 383 }
384 384
385 TEST_F(ObjectManagerTest, PropertiesChangedAsObjectsReceived) { 385 TEST_F(ObjectManagerTest, PropertiesChangedAsObjectsReceived) {
386 // Remove the existing object manager. 386 // Remove the existing object manager.
387 object_manager_->UnregisterInterface("org.chromium.TestInterface"); 387 object_manager_->UnregisterInterface("org.chromium.TestInterface");
388 run_loop_.reset(new base::RunLoop); 388 run_loop_.reset(new base::RunLoop);
389 EXPECT_TRUE(bus_->RemoveObjectManager( 389 EXPECT_TRUE(bus_->RemoveObjectManager(
390 "org.chromium.TestService", 390 test_service_->service_name(),
391 ObjectPath("/org/chromium/TestService"), 391 ObjectPath("/org/chromium/TestService"),
392 run_loop_->QuitClosure())); 392 run_loop_->QuitClosure()));
393 run_loop_->Run(); 393 run_loop_->Run();
394 394
395 PerformAction("SetSendImmediatePropertiesChanged", 395 PerformAction("SetSendImmediatePropertiesChanged",
396 ObjectPath("/org/chromium/TestService")); 396 ObjectPath("/org/chromium/TestService"));
397 397
398 object_manager_ = bus_->GetObjectManager( 398 object_manager_ = bus_->GetObjectManager(
399 "org.chromium.TestService", 399 test_service_->service_name(),
400 ObjectPath("/org/chromium/TestService")); 400 ObjectPath("/org/chromium/TestService"));
401 object_manager_->RegisterInterface("org.chromium.TestInterface", this); 401 object_manager_->RegisterInterface("org.chromium.TestInterface", this);
402 402
403 // The newly created object manager should call GetManagedObjects immediately 403 // The newly created object manager should call GetManagedObjects immediately
404 // after setting up the match rule for PropertiesChanged. We should process 404 // after setting up the match rule for PropertiesChanged. We should process
405 // the PropertiesChanged event right after that. If we don't receive it within 405 // the PropertiesChanged event right after that. If we don't receive it within
406 // 2 seconds, then fail the test. 406 // 2 seconds, then fail the test.
407 message_loop_.PostDelayedTask( 407 message_loop_.PostDelayedTask(
408 FROM_HERE, 408 FROM_HERE,
409 base::Bind(&ObjectManagerTest::PropertiesChangedTestTimeout, 409 base::Bind(&ObjectManagerTest::PropertiesChangedTestTimeout,
410 base::Unretained(this)), 410 base::Unretained(this)),
411 base::TimeDelta::FromSeconds(2)); 411 base::TimeDelta::FromSeconds(2));
412 412
413 while (last_name_value_ != "ChangedTestServiceName" && !timeout_expired_) { 413 while (last_name_value_ != "ChangedTestServiceName" && !timeout_expired_) {
414 run_loop_.reset(new base::RunLoop); 414 run_loop_.reset(new base::RunLoop);
415 run_loop_->Run(); 415 run_loop_->Run();
416 } 416 }
417 } 417 }
418 418
419 } // namespace dbus 419 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/end_to_end_sync_unittest.cc ('k') | dbus/object_proxy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698