| OLD | NEW |
| 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" |
| 11 #include "base/run_loop.h" |
| 11 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
| 12 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
| 13 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
| 14 #include "dbus/bus.h" | 15 #include "dbus/bus.h" |
| 15 #include "dbus/message.h" | 16 #include "dbus/message.h" |
| 16 #include "dbus/object_proxy.h" | 17 #include "dbus/object_proxy.h" |
| 17 #include "dbus/test_service.h" | 18 #include "dbus/test_service.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 namespace dbus { | 21 namespace dbus { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // Connect to the "Test" signal of "org.chromium.TestInterface" from | 59 // Connect to the "Test" signal of "org.chromium.TestInterface" from |
| 59 // the remote object. | 60 // the remote object. |
| 60 object_proxy_->ConnectToSignal( | 61 object_proxy_->ConnectToSignal( |
| 61 "org.chromium.TestInterface", | 62 "org.chromium.TestInterface", |
| 62 "Test", | 63 "Test", |
| 63 base::Bind(&SignalSenderVerificationTest::OnTestSignal, | 64 base::Bind(&SignalSenderVerificationTest::OnTestSignal, |
| 64 base::Unretained(this)), | 65 base::Unretained(this)), |
| 65 base::Bind(&SignalSenderVerificationTest::OnConnected, | 66 base::Bind(&SignalSenderVerificationTest::OnConnected, |
| 66 base::Unretained(this))); | 67 base::Unretained(this))); |
| 67 // Wait until the object proxy is connected to the signal. | 68 // Wait until the object proxy is connected to the signal. |
| 68 message_loop_.Run(); | 69 run_loop_.reset(new base::RunLoop); |
| 70 run_loop_->Run(); |
| 69 | 71 |
| 70 // Start the test service, using the D-Bus thread. | 72 // Start the test service, using the D-Bus thread. |
| 71 TestService::Options options; | 73 TestService::Options options; |
| 72 options.dbus_task_runner = dbus_thread_->message_loop_proxy(); | 74 options.dbus_task_runner = dbus_thread_->message_loop_proxy(); |
| 73 test_service_.reset(new TestService(options)); | 75 test_service_.reset(new TestService(options)); |
| 74 ASSERT_TRUE(test_service_->StartService()); | 76 ASSERT_TRUE(test_service_->StartService()); |
| 75 ASSERT_TRUE(test_service_->WaitUntilServiceIsStarted()); | 77 ASSERT_TRUE(test_service_->WaitUntilServiceIsStarted()); |
| 76 ASSERT_TRUE(test_service_->HasDBusThread()); | 78 ASSERT_TRUE(test_service_->HasDBusThread()); |
| 77 ASSERT_TRUE(test_service_->has_ownership()); | 79 ASSERT_TRUE(test_service_->has_ownership()); |
| 78 | 80 |
| 79 // Same setup for the second TestService. This service should not have the | 81 // Same setup for the second TestService. This service should not have the |
| 80 // ownership of the name at this point. | 82 // ownership of the name at this point. |
| 81 test_service2_.reset(new TestService(options)); | 83 test_service2_.reset(new TestService(options)); |
| 82 ASSERT_TRUE(test_service2_->StartService()); | 84 ASSERT_TRUE(test_service2_->StartService()); |
| 83 ASSERT_TRUE(test_service2_->WaitUntilServiceIsStarted()); | 85 ASSERT_TRUE(test_service2_->WaitUntilServiceIsStarted()); |
| 84 ASSERT_TRUE(test_service2_->HasDBusThread()); | 86 ASSERT_TRUE(test_service2_->HasDBusThread()); |
| 85 ASSERT_FALSE(test_service2_->has_ownership()); | 87 ASSERT_FALSE(test_service2_->has_ownership()); |
| 86 | 88 |
| 87 // The name should be owned and known at this point. | 89 // The name should be owned and known at this point. |
| 88 if (!on_name_owner_changed_called_) | 90 if (!on_name_owner_changed_called_) { |
| 89 message_loop_.Run(); | 91 run_loop_.reset(new base::RunLoop); |
| 92 run_loop_->Run(); |
| 93 } |
| 90 ASSERT_FALSE(latest_name_owner_.empty()); | 94 ASSERT_FALSE(latest_name_owner_.empty()); |
| 91 } | 95 } |
| 92 | 96 |
| 93 virtual void TearDown() { | 97 virtual void TearDown() { |
| 94 bus_->ShutdownOnDBusThreadAndBlock(); | 98 bus_->ShutdownOnDBusThreadAndBlock(); |
| 95 | 99 |
| 96 // Shut down the service. | 100 // Shut down the service. |
| 97 test_service_->ShutdownAndBlock(); | 101 test_service_->ShutdownAndBlock(); |
| 98 test_service2_->ShutdownAndBlock(); | 102 test_service2_->ShutdownAndBlock(); |
| 99 | 103 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 110 ASSERT_EQ(expected, success); | 114 ASSERT_EQ(expected, success); |
| 111 // PostTask to quit the MessageLoop as this is called from D-Bus thread. | 115 // PostTask to quit the MessageLoop as this is called from D-Bus thread. |
| 112 message_loop_.PostTask( | 116 message_loop_.PostTask( |
| 113 FROM_HERE, | 117 FROM_HERE, |
| 114 base::Bind(&SignalSenderVerificationTest::OnOwnershipInternal, | 118 base::Bind(&SignalSenderVerificationTest::OnOwnershipInternal, |
| 115 base::Unretained(this))); | 119 base::Unretained(this))); |
| 116 } | 120 } |
| 117 | 121 |
| 118 void OnOwnershipInternal() { | 122 void OnOwnershipInternal() { |
| 119 on_ownership_called_ = true; | 123 on_ownership_called_ = true; |
| 120 message_loop_.Quit(); | 124 run_loop_->Quit(); |
| 121 } | 125 } |
| 122 | 126 |
| 123 void OnNameOwnerChanged(bool* called_flag, | 127 void OnNameOwnerChanged(bool* called_flag, |
| 124 const std::string& old_owner, | 128 const std::string& old_owner, |
| 125 const std::string& new_owner) { | 129 const std::string& new_owner) { |
| 126 latest_name_owner_ = new_owner; | 130 latest_name_owner_ = new_owner; |
| 127 *called_flag = true; | 131 *called_flag = true; |
| 128 message_loop_.Quit(); | 132 run_loop_->Quit(); |
| 129 } | 133 } |
| 130 | 134 |
| 131 // Called when the "Test" signal is received, in the main thread. | 135 // Called when the "Test" signal is received, in the main thread. |
| 132 // Copy the string payload to |test_signal_string_|. | 136 // Copy the string payload to |test_signal_string_|. |
| 133 void OnTestSignal(Signal* signal) { | 137 void OnTestSignal(Signal* signal) { |
| 134 MessageReader reader(signal); | 138 MessageReader reader(signal); |
| 135 ASSERT_TRUE(reader.PopString(&test_signal_string_)); | 139 ASSERT_TRUE(reader.PopString(&test_signal_string_)); |
| 136 message_loop_.Quit(); | 140 run_loop_->Quit(); |
| 137 } | 141 } |
| 138 | 142 |
| 139 // Called when connected to the signal. | 143 // Called when connected to the signal. |
| 140 void OnConnected(const std::string& interface_name, | 144 void OnConnected(const std::string& interface_name, |
| 141 const std::string& signal_name, | 145 const std::string& signal_name, |
| 142 bool success) { | 146 bool success) { |
| 143 ASSERT_TRUE(success); | 147 ASSERT_TRUE(success); |
| 144 message_loop_.Quit(); | 148 run_loop_->Quit(); |
| 145 } | 149 } |
| 146 | 150 |
| 147 protected: | 151 protected: |
| 148 // Wait for the hey signal to be received. | 152 // Wait for the hey signal to be received. |
| 149 void WaitForTestSignal() { | 153 void WaitForTestSignal() { |
| 150 // OnTestSignal() will quit the message loop. | 154 // OnTestSignal() will quit the message loop. |
| 151 message_loop_.Run(); | 155 run_loop_.reset(new base::RunLoop); |
| 156 run_loop_->Run(); |
| 152 } | 157 } |
| 153 | 158 |
| 154 // Stopping a thread is considered an IO operation, so we need to fiddle with | 159 // Stopping a thread is considered an IO operation, so we need to fiddle with |
| 155 // thread restrictions before and after calling Stop() on a TestService. | 160 // thread restrictions before and after calling Stop() on a TestService. |
| 156 void SafeServiceStop(TestService* test_service) { | 161 void SafeServiceStop(TestService* test_service) { |
| 157 base::ThreadRestrictions::SetIOAllowed(true); | 162 base::ThreadRestrictions::SetIOAllowed(true); |
| 158 test_service->Stop(); | 163 test_service->Stop(); |
| 159 base::ThreadRestrictions::SetIOAllowed(false); | 164 base::ThreadRestrictions::SetIOAllowed(false); |
| 160 } | 165 } |
| 161 | 166 |
| 162 base::MessageLoop message_loop_; | 167 base::MessageLoop message_loop_; |
| 168 scoped_ptr<base::RunLoop> run_loop_; |
| 163 scoped_ptr<base::Thread> dbus_thread_; | 169 scoped_ptr<base::Thread> dbus_thread_; |
| 164 scoped_refptr<Bus> bus_; | 170 scoped_refptr<Bus> bus_; |
| 165 ObjectProxy* object_proxy_; | 171 ObjectProxy* object_proxy_; |
| 166 scoped_ptr<TestService> test_service_; | 172 scoped_ptr<TestService> test_service_; |
| 167 scoped_ptr<TestService> test_service2_; | 173 scoped_ptr<TestService> test_service2_; |
| 168 // Text message from "Test" signal. | 174 // Text message from "Test" signal. |
| 169 std::string test_signal_string_; | 175 std::string test_signal_string_; |
| 170 | 176 |
| 171 // The known latest name owner of TestService. Updated in OnNameOwnerChanged. | 177 // The known latest name owner of TestService. Updated in OnNameOwnerChanged. |
| 172 std::string latest_name_owner_; | 178 std::string latest_name_owner_; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 // Receive the signal with the object proxy. The signal is handled in | 223 // Receive the signal with the object proxy. The signal is handled in |
| 218 // SignalSenderVerificationTest::OnTestSignal() in the main thread. | 224 // SignalSenderVerificationTest::OnTestSignal() in the main thread. |
| 219 WaitForTestSignal(); | 225 WaitForTestSignal(); |
| 220 ASSERT_EQ(kMessage, test_signal_string_); | 226 ASSERT_EQ(kMessage, test_signal_string_); |
| 221 | 227 |
| 222 // Release and acquire the name ownership. | 228 // Release and acquire the name ownership. |
| 223 // latest_name_owner_ should be non empty as |test_service_| owns the name. | 229 // latest_name_owner_ should be non empty as |test_service_| owns the name. |
| 224 ASSERT_FALSE(latest_name_owner_.empty()); | 230 ASSERT_FALSE(latest_name_owner_.empty()); |
| 225 test_service_->ShutdownAndBlock(); | 231 test_service_->ShutdownAndBlock(); |
| 226 // OnNameOwnerChanged will PostTask to quit the message loop. | 232 // OnNameOwnerChanged will PostTask to quit the message loop. |
| 227 message_loop_.Run(); | 233 run_loop_.reset(new base::RunLoop); |
| 234 run_loop_->Run(); |
| 228 // latest_name_owner_ should be empty as the owner is gone. | 235 // latest_name_owner_ should be empty as the owner is gone. |
| 229 ASSERT_TRUE(latest_name_owner_.empty()); | 236 ASSERT_TRUE(latest_name_owner_.empty()); |
| 230 | 237 |
| 231 // Reset the flag as NameOwnerChanged is already received in setup. | 238 // Reset the flag as NameOwnerChanged is already received in setup. |
| 232 on_name_owner_changed_called_ = false; | 239 on_name_owner_changed_called_ = false; |
| 233 on_ownership_called_ = false; | 240 on_ownership_called_ = false; |
| 234 test_service2_->RequestOwnership( | 241 test_service2_->RequestOwnership( |
| 235 base::Bind(&SignalSenderVerificationTest::OnOwnership, | 242 base::Bind(&SignalSenderVerificationTest::OnOwnership, |
| 236 base::Unretained(this), true)); | 243 base::Unretained(this), true)); |
| 237 // Both of OnNameOwnerChanged() and OnOwnership() should quit the MessageLoop, | 244 // Both of OnNameOwnerChanged() and OnOwnership() should quit the MessageLoop, |
| 238 // but there's no expected order of those 2 event. | 245 // but there's no expected order of those 2 event. |
| 239 message_loop_.Run(); | 246 run_loop_.reset(new base::RunLoop); |
| 240 if (!on_name_owner_changed_called_ || !on_ownership_called_) | 247 run_loop_->Run(); |
| 241 message_loop_.Run(); | 248 if (!on_name_owner_changed_called_ || !on_ownership_called_) { |
| 249 run_loop_.reset(new base::RunLoop); |
| 250 run_loop_->Run(); |
| 251 } |
| 242 ASSERT_TRUE(on_name_owner_changed_called_); | 252 ASSERT_TRUE(on_name_owner_changed_called_); |
| 243 ASSERT_TRUE(on_ownership_called_); | 253 ASSERT_TRUE(on_ownership_called_); |
| 244 | 254 |
| 245 // latest_name_owner_ becomes non empty as the new owner appears. | 255 // latest_name_owner_ becomes non empty as the new owner appears. |
| 246 ASSERT_FALSE(latest_name_owner_.empty()); | 256 ASSERT_FALSE(latest_name_owner_.empty()); |
| 247 | 257 |
| 248 // Now the second service owns the name. | 258 // Now the second service owns the name. |
| 249 const char kNewMessage[] = "hello, new world"; | 259 const char kNewMessage[] = "hello, new world"; |
| 250 | 260 |
| 251 test_service2_->SendTestSignal(kNewMessage); | 261 test_service2_->SendTestSignal(kNewMessage); |
| 252 WaitForTestSignal(); | 262 WaitForTestSignal(); |
| 253 ASSERT_EQ(kNewMessage, test_signal_string_); | 263 ASSERT_EQ(kNewMessage, test_signal_string_); |
| 254 } | 264 } |
| 255 | 265 |
| 256 TEST_F(SignalSenderVerificationTest, TestOwnerStealing) { | 266 TEST_F(SignalSenderVerificationTest, TestOwnerStealing) { |
| 257 // Release and acquire the name ownership. | 267 // Release and acquire the name ownership. |
| 258 // latest_name_owner_ should be non empty as |test_service_| owns the name. | 268 // latest_name_owner_ should be non empty as |test_service_| owns the name. |
| 259 ASSERT_FALSE(latest_name_owner_.empty()); | 269 ASSERT_FALSE(latest_name_owner_.empty()); |
| 260 test_service_->ShutdownAndBlock(); | 270 test_service_->ShutdownAndBlock(); |
| 261 // OnNameOwnerChanged will PostTask to quit the message loop. | 271 // OnNameOwnerChanged will PostTask to quit the message loop. |
| 262 message_loop_.Run(); | 272 run_loop_.reset(new base::RunLoop); |
| 273 run_loop_->Run(); |
| 263 // latest_name_owner_ should be empty as the owner is gone. | 274 // latest_name_owner_ should be empty as the owner is gone. |
| 264 ASSERT_TRUE(latest_name_owner_.empty()); | 275 ASSERT_TRUE(latest_name_owner_.empty()); |
| 265 // Reset the flag as NameOwnerChanged is already received in setup. | 276 // Reset the flag as NameOwnerChanged is already received in setup. |
| 266 on_name_owner_changed_called_ = false; | 277 on_name_owner_changed_called_ = false; |
| 267 | 278 |
| 268 // Start a test service that allows theft, using the D-Bus thread. | 279 // Start a test service that allows theft, using the D-Bus thread. |
| 269 TestService::Options options; | 280 TestService::Options options; |
| 270 options.dbus_task_runner = dbus_thread_->message_loop_proxy(); | 281 options.dbus_task_runner = dbus_thread_->message_loop_proxy(); |
| 271 options.request_ownership_options = Bus::REQUIRE_PRIMARY_ALLOW_REPLACEMENT; | 282 options.request_ownership_options = Bus::REQUIRE_PRIMARY_ALLOW_REPLACEMENT; |
| 272 TestService stealable_test_service(options); | 283 TestService stealable_test_service(options); |
| 273 ASSERT_TRUE(stealable_test_service.StartService()); | 284 ASSERT_TRUE(stealable_test_service.StartService()); |
| 274 ASSERT_TRUE(stealable_test_service.WaitUntilServiceIsStarted()); | 285 ASSERT_TRUE(stealable_test_service.WaitUntilServiceIsStarted()); |
| 275 ASSERT_TRUE(stealable_test_service.HasDBusThread()); | 286 ASSERT_TRUE(stealable_test_service.HasDBusThread()); |
| 276 ASSERT_TRUE(stealable_test_service.has_ownership()); | 287 ASSERT_TRUE(stealable_test_service.has_ownership()); |
| 277 | 288 |
| 278 // OnNameOwnerChanged will PostTask to quit the message loop. | 289 // OnNameOwnerChanged will PostTask to quit the message loop. |
| 279 message_loop_.Run(); | 290 run_loop_.reset(new base::RunLoop); |
| 291 run_loop_->Run(); |
| 280 | 292 |
| 281 // Send a signal to check that the service is correctly owned. | 293 // Send a signal to check that the service is correctly owned. |
| 282 const char kMessage[] = "hello, world"; | 294 const char kMessage[] = "hello, world"; |
| 283 | 295 |
| 284 // Send the test signal from the exported object. | 296 // Send the test signal from the exported object. |
| 285 stealable_test_service.SendTestSignal(kMessage); | 297 stealable_test_service.SendTestSignal(kMessage); |
| 286 // Receive the signal with the object proxy. The signal is handled in | 298 // Receive the signal with the object proxy. The signal is handled in |
| 287 // SignalSenderVerificationTest::OnTestSignal() in the main thread. | 299 // SignalSenderVerificationTest::OnTestSignal() in the main thread. |
| 288 WaitForTestSignal(); | 300 WaitForTestSignal(); |
| 289 ASSERT_EQ(kMessage, test_signal_string_); | 301 ASSERT_EQ(kMessage, test_signal_string_); |
| 290 | 302 |
| 291 // Reset the flag as NameOwnerChanged was called above. | 303 // Reset the flag as NameOwnerChanged was called above. |
| 292 on_name_owner_changed_called_ = false; | 304 on_name_owner_changed_called_ = false; |
| 293 test_service2_->RequestOwnership( | 305 test_service2_->RequestOwnership( |
| 294 base::Bind(&SignalSenderVerificationTest::OnOwnership, | 306 base::Bind(&SignalSenderVerificationTest::OnOwnership, |
| 295 base::Unretained(this), true)); | 307 base::Unretained(this), true)); |
| 296 // Both of OnNameOwnerChanged() and OnOwnership() should quit the MessageLoop, | 308 // Both of OnNameOwnerChanged() and OnOwnership() should quit the MessageLoop, |
| 297 // but there's no expected order of those 2 event. | 309 // but there's no expected order of those 2 event. |
| 298 message_loop_.Run(); | 310 run_loop_.reset(new base::RunLoop); |
| 299 if (!on_name_owner_changed_called_ || !on_ownership_called_) | 311 run_loop_->Run(); |
| 300 message_loop_.Run(); | 312 if (!on_name_owner_changed_called_ || !on_ownership_called_) { |
| 313 run_loop_.reset(new base::RunLoop); |
| 314 run_loop_->Run(); |
| 315 } |
| 301 ASSERT_TRUE(on_name_owner_changed_called_); | 316 ASSERT_TRUE(on_name_owner_changed_called_); |
| 302 ASSERT_TRUE(on_ownership_called_); | 317 ASSERT_TRUE(on_ownership_called_); |
| 303 | 318 |
| 304 // Now the second service owns the name. | 319 // Now the second service owns the name. |
| 305 const char kNewMessage[] = "hello, new world"; | 320 const char kNewMessage[] = "hello, new world"; |
| 306 | 321 |
| 307 test_service2_->SendTestSignal(kNewMessage); | 322 test_service2_->SendTestSignal(kNewMessage); |
| 308 WaitForTestSignal(); | 323 WaitForTestSignal(); |
| 309 ASSERT_EQ(kNewMessage, test_signal_string_); | 324 ASSERT_EQ(kNewMessage, test_signal_string_); |
| 310 | 325 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 328 // Connect to a signal on the additional remote object to trigger the | 343 // Connect to a signal on the additional remote object to trigger the |
| 329 // name owner matching. | 344 // name owner matching. |
| 330 object_proxy2->ConnectToSignal( | 345 object_proxy2->ConnectToSignal( |
| 331 "org.chromium.DifferentTestInterface", | 346 "org.chromium.DifferentTestInterface", |
| 332 "Test", | 347 "Test", |
| 333 base::Bind(&SignalSenderVerificationTest::OnTestSignal, | 348 base::Bind(&SignalSenderVerificationTest::OnTestSignal, |
| 334 base::Unretained(this)), | 349 base::Unretained(this)), |
| 335 base::Bind(&SignalSenderVerificationTest::OnConnected, | 350 base::Bind(&SignalSenderVerificationTest::OnConnected, |
| 336 base::Unretained(this))); | 351 base::Unretained(this))); |
| 337 // Wait until the object proxy is connected to the signal. | 352 // Wait until the object proxy is connected to the signal. |
| 338 message_loop_.Run(); | 353 run_loop_.reset(new base::RunLoop); |
| 354 run_loop_->Run(); |
| 339 | 355 |
| 340 // Send the test signal from the exported object. | 356 // Send the test signal from the exported object. |
| 341 test_service_->SendTestSignal(kMessage); | 357 test_service_->SendTestSignal(kMessage); |
| 342 // Receive the signal with the object proxy. The signal is handled in | 358 // Receive the signal with the object proxy. The signal is handled in |
| 343 // SignalSenderVerificationTest::OnTestSignal() in the main thread. | 359 // SignalSenderVerificationTest::OnTestSignal() in the main thread. |
| 344 WaitForTestSignal(); | 360 WaitForTestSignal(); |
| 345 ASSERT_EQ(kMessage, test_signal_string_); | 361 ASSERT_EQ(kMessage, test_signal_string_); |
| 346 | 362 |
| 347 // Release and acquire the name ownership. | 363 // Release and acquire the name ownership. |
| 348 // latest_name_owner_ should be non empty as |test_service_| owns the name. | 364 // latest_name_owner_ should be non empty as |test_service_| owns the name. |
| 349 ASSERT_FALSE(latest_name_owner_.empty()); | 365 ASSERT_FALSE(latest_name_owner_.empty()); |
| 350 test_service_->ShutdownAndBlock(); | 366 test_service_->ShutdownAndBlock(); |
| 351 // OnNameOwnerChanged will PostTask to quit the message loop. | 367 // OnNameOwnerChanged will PostTask to quit the message loop. |
| 352 message_loop_.Run(); | 368 run_loop_.reset(new base::RunLoop); |
| 369 run_loop_->Run(); |
| 353 // latest_name_owner_ should be empty as the owner is gone. | 370 // latest_name_owner_ should be empty as the owner is gone. |
| 354 ASSERT_TRUE(latest_name_owner_.empty()); | 371 ASSERT_TRUE(latest_name_owner_.empty()); |
| 355 | 372 |
| 356 // Reset the flag as NameOwnerChanged is already received in setup. | 373 // Reset the flag as NameOwnerChanged is already received in setup. |
| 357 on_name_owner_changed_called_ = false; | 374 on_name_owner_changed_called_ = false; |
| 358 second_name_owner_changed_called = false; | 375 second_name_owner_changed_called = false; |
| 359 test_service2_->RequestOwnership( | 376 test_service2_->RequestOwnership( |
| 360 base::Bind(&SignalSenderVerificationTest::OnOwnership, | 377 base::Bind(&SignalSenderVerificationTest::OnOwnership, |
| 361 base::Unretained(this), true)); | 378 base::Unretained(this), true)); |
| 362 // Both of OnNameOwnerChanged() and OnOwnership() should quit the MessageLoop, | 379 // Both of OnNameOwnerChanged() and OnOwnership() should quit the MessageLoop, |
| 363 // but there's no expected order of those 2 event. | 380 // but there's no expected order of those 2 event. |
| 364 while (!on_name_owner_changed_called_ || !second_name_owner_changed_called || | 381 while (!on_name_owner_changed_called_ || !second_name_owner_changed_called || |
| 365 !on_ownership_called_) | 382 !on_ownership_called_) { |
| 366 message_loop_.Run(); | 383 run_loop_.reset(new base::RunLoop); |
| 384 run_loop_->Run(); |
| 385 } |
| 367 ASSERT_TRUE(on_name_owner_changed_called_); | 386 ASSERT_TRUE(on_name_owner_changed_called_); |
| 368 ASSERT_TRUE(second_name_owner_changed_called); | 387 ASSERT_TRUE(second_name_owner_changed_called); |
| 369 ASSERT_TRUE(on_ownership_called_); | 388 ASSERT_TRUE(on_ownership_called_); |
| 370 | 389 |
| 371 // latest_name_owner_ becomes non empty as the new owner appears. | 390 // latest_name_owner_ becomes non empty as the new owner appears. |
| 372 ASSERT_FALSE(latest_name_owner_.empty()); | 391 ASSERT_FALSE(latest_name_owner_.empty()); |
| 373 | 392 |
| 374 // Now the second service owns the name. | 393 // Now the second service owns the name. |
| 375 const char kNewMessage[] = "hello, new world"; | 394 const char kNewMessage[] = "hello, new world"; |
| 376 | 395 |
| 377 test_service2_->SendTestSignal(kNewMessage); | 396 test_service2_->SendTestSignal(kNewMessage); |
| 378 WaitForTestSignal(); | 397 WaitForTestSignal(); |
| 379 ASSERT_EQ(kNewMessage, test_signal_string_); | 398 ASSERT_EQ(kNewMessage, test_signal_string_); |
| 380 } | 399 } |
| 381 | 400 |
| 382 } // namespace dbus | 401 } // namespace dbus |
| OLD | NEW |