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

Side by Side Diff: dbus/signal_sender_verification_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/property_unittest.cc ('k') | dbus/test_service.h » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/metrics/histogram_samples.h" 9 #include "base/metrics/histogram_samples.h"
10 #include "base/metrics/statistics_recorder.h" 10 #include "base/metrics/statistics_recorder.h"
(...skipping 22 matching lines...) Expand all
33 33
34 // Make the main thread not to allow IO. 34 // Make the main thread not to allow IO.
35 base::ThreadRestrictions::SetIOAllowed(false); 35 base::ThreadRestrictions::SetIOAllowed(false);
36 36
37 // Start the D-Bus thread. 37 // Start the D-Bus thread.
38 dbus_thread_.reset(new base::Thread("D-Bus Thread")); 38 dbus_thread_.reset(new base::Thread("D-Bus Thread"));
39 base::Thread::Options thread_options; 39 base::Thread::Options thread_options;
40 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; 40 thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
41 ASSERT_TRUE(dbus_thread_->StartWithOptions(thread_options)); 41 ASSERT_TRUE(dbus_thread_->StartWithOptions(thread_options));
42 42
43 // Create the test service, using the D-Bus thread.
44 TestService::Options options;
45 options.dbus_task_runner = dbus_thread_->task_runner();
46 test_service_.reset(new TestService(options));
47
43 // Create the client, using the D-Bus thread. 48 // Create the client, using the D-Bus thread.
44 Bus::Options bus_options; 49 Bus::Options bus_options;
45 bus_options.bus_type = Bus::SESSION; 50 bus_options.bus_type = Bus::SESSION;
46 bus_options.connection_type = Bus::PRIVATE; 51 bus_options.connection_type = Bus::PRIVATE;
47 bus_options.dbus_task_runner = dbus_thread_->task_runner(); 52 bus_options.dbus_task_runner = dbus_thread_->task_runner();
48 bus_ = new Bus(bus_options); 53 bus_ = new Bus(bus_options);
49 object_proxy_ = bus_->GetObjectProxy( 54 object_proxy_ = bus_->GetObjectProxy(
50 "org.chromium.TestService", 55 test_service_->service_name(),
51 ObjectPath("/org/chromium/TestObject")); 56 ObjectPath("/org/chromium/TestObject"));
52 ASSERT_TRUE(bus_->HasDBusThread()); 57 ASSERT_TRUE(bus_->HasDBusThread());
53 58
54 object_proxy_->SetNameOwnerChangedCallback( 59 object_proxy_->SetNameOwnerChangedCallback(
55 base::Bind(&SignalSenderVerificationTest::OnNameOwnerChanged, 60 base::Bind(&SignalSenderVerificationTest::OnNameOwnerChanged,
56 base::Unretained(this), 61 base::Unretained(this),
57 &on_name_owner_changed_called_)); 62 &on_name_owner_changed_called_));
58 63
59 // Connect to the "Test" signal of "org.chromium.TestInterface" from 64 // Connect to the "Test" signal of "org.chromium.TestInterface" from
60 // the remote object. 65 // the remote object.
61 object_proxy_->ConnectToSignal( 66 object_proxy_->ConnectToSignal(
62 "org.chromium.TestInterface", 67 "org.chromium.TestInterface",
63 "Test", 68 "Test",
64 base::Bind(&SignalSenderVerificationTest::OnTestSignal, 69 base::Bind(&SignalSenderVerificationTest::OnTestSignal,
65 base::Unretained(this)), 70 base::Unretained(this)),
66 base::Bind(&SignalSenderVerificationTest::OnConnected, 71 base::Bind(&SignalSenderVerificationTest::OnConnected,
67 base::Unretained(this))); 72 base::Unretained(this)));
68 // Wait until the object proxy is connected to the signal. 73 // Wait until the object proxy is connected to the signal.
69 run_loop_.reset(new base::RunLoop); 74 run_loop_.reset(new base::RunLoop);
70 run_loop_->Run(); 75 run_loop_->Run();
71 76
72 // Start the test service, using the D-Bus thread. 77 // Start the test service.
73 TestService::Options options;
74 options.dbus_task_runner = dbus_thread_->task_runner();
75 test_service_.reset(new TestService(options));
76 ASSERT_TRUE(test_service_->StartService()); 78 ASSERT_TRUE(test_service_->StartService());
77 ASSERT_TRUE(test_service_->WaitUntilServiceIsStarted()); 79 ASSERT_TRUE(test_service_->WaitUntilServiceIsStarted());
78 ASSERT_TRUE(test_service_->HasDBusThread()); 80 ASSERT_TRUE(test_service_->HasDBusThread());
79 ASSERT_TRUE(test_service_->has_ownership()); 81 ASSERT_TRUE(test_service_->has_ownership());
80 82
81 // Same setup for the second TestService. This service should not have the 83 // Same setup for the second TestService. This service should not have the
82 // ownership of the name at this point. 84 // ownership of the name at this point.
85 options.service_name = test_service_->service_name();
83 test_service2_.reset(new TestService(options)); 86 test_service2_.reset(new TestService(options));
84 ASSERT_TRUE(test_service2_->StartService()); 87 ASSERT_TRUE(test_service2_->StartService());
85 ASSERT_TRUE(test_service2_->WaitUntilServiceIsStarted()); 88 ASSERT_TRUE(test_service2_->WaitUntilServiceIsStarted());
86 ASSERT_TRUE(test_service2_->HasDBusThread()); 89 ASSERT_TRUE(test_service2_->HasDBusThread());
87 ASSERT_FALSE(test_service2_->has_ownership()); 90 ASSERT_FALSE(test_service2_->has_ownership());
88 91
89 // The name should be owned and known at this point. 92 // The name should be owned and known at this point.
90 if (!on_name_owner_changed_called_) { 93 if (!on_name_owner_changed_called_) {
91 run_loop_.reset(new base::RunLoop); 94 run_loop_.reset(new base::RunLoop);
92 run_loop_->Run(); 95 run_loop_->Run();
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 run_loop_->Run(); 276 run_loop_->Run();
274 // latest_name_owner_ should be empty as the owner is gone. 277 // latest_name_owner_ should be empty as the owner is gone.
275 ASSERT_TRUE(latest_name_owner_.empty()); 278 ASSERT_TRUE(latest_name_owner_.empty());
276 // Reset the flag as NameOwnerChanged is already received in setup. 279 // Reset the flag as NameOwnerChanged is already received in setup.
277 on_name_owner_changed_called_ = false; 280 on_name_owner_changed_called_ = false;
278 281
279 // Start a test service that allows theft, using the D-Bus thread. 282 // Start a test service that allows theft, using the D-Bus thread.
280 TestService::Options options; 283 TestService::Options options;
281 options.dbus_task_runner = dbus_thread_->task_runner(); 284 options.dbus_task_runner = dbus_thread_->task_runner();
282 options.request_ownership_options = Bus::REQUIRE_PRIMARY_ALLOW_REPLACEMENT; 285 options.request_ownership_options = Bus::REQUIRE_PRIMARY_ALLOW_REPLACEMENT;
286 options.service_name = test_service_->service_name();
283 TestService stealable_test_service(options); 287 TestService stealable_test_service(options);
284 ASSERT_TRUE(stealable_test_service.StartService()); 288 ASSERT_TRUE(stealable_test_service.StartService());
285 ASSERT_TRUE(stealable_test_service.WaitUntilServiceIsStarted()); 289 ASSERT_TRUE(stealable_test_service.WaitUntilServiceIsStarted());
286 ASSERT_TRUE(stealable_test_service.HasDBusThread()); 290 ASSERT_TRUE(stealable_test_service.HasDBusThread());
287 ASSERT_TRUE(stealable_test_service.has_ownership()); 291 ASSERT_TRUE(stealable_test_service.has_ownership());
288 292
289 // OnNameOwnerChanged will PostTask to quit the message loop. 293 // OnNameOwnerChanged will PostTask to quit the message loop.
290 run_loop_.reset(new base::RunLoop); 294 run_loop_.reset(new base::RunLoop);
291 run_loop_->Run(); 295 run_loop_->Run();
292 296
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 ASSERT_EQ(kNewMessage, test_signal_string_); 328 ASSERT_EQ(kNewMessage, test_signal_string_);
325 329
326 SafeServiceStop(&stealable_test_service); 330 SafeServiceStop(&stealable_test_service);
327 } 331 }
328 332
329 // Fails on Linux ChromiumOS Tests 333 // Fails on Linux ChromiumOS Tests
330 TEST_F(SignalSenderVerificationTest, DISABLED_TestMultipleObjects) { 334 TEST_F(SignalSenderVerificationTest, DISABLED_TestMultipleObjects) {
331 const char kMessage[] = "hello, world"; 335 const char kMessage[] = "hello, world";
332 336
333 ObjectProxy* object_proxy2 = bus_->GetObjectProxy( 337 ObjectProxy* object_proxy2 = bus_->GetObjectProxy(
334 "org.chromium.TestService", 338 test_service_->service_name(),
335 ObjectPath("/org/chromium/DifferentObject")); 339 ObjectPath("/org/chromium/DifferentObject"));
336 340
337 bool second_name_owner_changed_called = false; 341 bool second_name_owner_changed_called = false;
338 object_proxy2->SetNameOwnerChangedCallback( 342 object_proxy2->SetNameOwnerChangedCallback(
339 base::Bind(&SignalSenderVerificationTest::OnNameOwnerChanged, 343 base::Bind(&SignalSenderVerificationTest::OnNameOwnerChanged,
340 base::Unretained(this), 344 base::Unretained(this),
341 &second_name_owner_changed_called)); 345 &second_name_owner_changed_called));
342 346
343 // Connect to a signal on the additional remote object to trigger the 347 // Connect to a signal on the additional remote object to trigger the
344 // name owner matching. 348 // name owner matching.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 396
393 // Now the second service owns the name. 397 // Now the second service owns the name.
394 const char kNewMessage[] = "hello, new world"; 398 const char kNewMessage[] = "hello, new world";
395 399
396 test_service2_->SendTestSignal(kNewMessage); 400 test_service2_->SendTestSignal(kNewMessage);
397 WaitForTestSignal(); 401 WaitForTestSignal();
398 ASSERT_EQ(kNewMessage, test_signal_string_); 402 ASSERT_EQ(kNewMessage, test_signal_string_);
399 } 403 }
400 404
401 } // namespace dbus 405 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/property_unittest.cc ('k') | dbus/test_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698