Chromium Code Reviews| Index: dbus/signal_sender_verification_unittest.cc |
| diff --git a/dbus/signal_sender_verification_unittest.cc b/dbus/signal_sender_verification_unittest.cc |
| index df2acd2cf466e765acfbe2e92109cbede433c8a4..34612234f0c19796dd791547fd7649ccfcdd3e11 100644 |
| --- a/dbus/signal_sender_verification_unittest.cc |
| +++ b/dbus/signal_sender_verification_unittest.cc |
| @@ -224,6 +224,7 @@ TEST_F(SignalSenderVerificationTest, TestOwnerChanged) { |
| // Reset the flag as NameOwnerChanged is already received in setup. |
| on_name_owner_changed_called_ = false; |
| + on_ownership_called_ = false; |
| test_service2_->RequestOwnership( |
| base::Bind(&SignalSenderVerificationTest::OnOwnership, |
| base::Unretained(this), true)); |
| @@ -246,6 +247,64 @@ TEST_F(SignalSenderVerificationTest, TestOwnerChanged) { |
| ASSERT_EQ(kNewMessage, test_signal_string_); |
| } |
| +TEST_F(SignalSenderVerificationTest, TestOwnerStealing) { |
| + // Release and acquire the name ownership. |
| + // latest_name_owner_ should be non empty as |test_service_| owns the name. |
| + ASSERT_FALSE(latest_name_owner_.empty()); |
| + test_service_->ShutdownAndBlock(); |
| + // OnNameOwnerChanged will PostTask to quit the message loop. |
| + message_loop_.Run(); |
| + // latest_name_owner_ should be empty as the owner is gone. |
| + ASSERT_TRUE(latest_name_owner_.empty()); |
| + // Reset the flag as NameOwnerChanged is already received in setup. |
| + on_name_owner_changed_called_ = false; |
| + |
| + // Start a test service that allows theft, using the D-Bus thread. |
| + TestService::Options options; |
| + options.dbus_task_runner = dbus_thread_->message_loop_proxy(); |
| + options.request_ownership_options = Bus::REQUIRE_PRIMARY_ALLOW_REPLACEMENT; |
| + TestService stealable_test_service(options); |
| + ASSERT_TRUE(stealable_test_service.StartService()); |
| + ASSERT_TRUE(stealable_test_service.WaitUntilServiceIsStarted()); |
| + ASSERT_TRUE(stealable_test_service.HasDBusThread()); |
| + ASSERT_TRUE(stealable_test_service.has_ownership()); |
| + |
| + LOG(INFO) << "Spun up new test service"; |
|
satorux1
2013/07/26 00:50:12
please remove this.
Chris Masone
2013/07/26 17:37:24
Done.
|
| + |
| + // OnNameOwnerChanged will PostTask to quit the message loop. |
| + message_loop_.Run(); |
| + |
| + // Send a signal to check that the service is correctly owned. |
| + const char kMessage[] = "hello, world"; |
| + |
| + // Send the test signal from the exported object. |
| + stealable_test_service.SendTestSignal(kMessage); |
| + // Receive the signal with the object proxy. The signal is handled in |
| + // SignalSenderVerificationTest::OnTestSignal() in the main thread. |
| + WaitForTestSignal(); |
| + ASSERT_EQ(kMessage, test_signal_string_); |
| + |
| + // Reset the flag as NameOwnerChanged was called above. |
| + on_name_owner_changed_called_ = false; |
| + test_service2_->RequestOwnership( |
| + base::Bind(&SignalSenderVerificationTest::OnOwnership, |
| + base::Unretained(this), true)); |
| + // Both of OnNameOwnerChanged() and OnOwnership() should quit the MessageLoop, |
| + // but there's no expected order of those 2 event. |
| + message_loop_.Run(); |
| + if (!on_name_owner_changed_called_ || !on_ownership_called_) |
| + message_loop_.Run(); |
| + ASSERT_TRUE(on_name_owner_changed_called_); |
| + ASSERT_TRUE(on_ownership_called_); |
| + |
| + // Now the second service owns the name. |
| + const char kNewMessage[] = "hello, new world"; |
| + |
| + test_service2_->SendTestSignal(kNewMessage); |
| + WaitForTestSignal(); |
| + ASSERT_EQ(kNewMessage, test_signal_string_); |
| +} |
| + |
| // Fails on Linux ChromiumOS Tests |
| TEST_F(SignalSenderVerificationTest, DISABLED_TestMultipleObjects) { |
| const char kMessage[] = "hello, world"; |