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

Side by Side Diff: dbus/signal_sender_verification_unittest.cc

Issue 20555003: Allow Chromium's DBus service ownership to be stealable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // latest_name_owner_ should be non empty as |test_service_| owns the name. 217 // latest_name_owner_ should be non empty as |test_service_| owns the name.
218 ASSERT_FALSE(latest_name_owner_.empty()); 218 ASSERT_FALSE(latest_name_owner_.empty());
219 test_service_->ShutdownAndBlock(); 219 test_service_->ShutdownAndBlock();
220 // OnNameOwnerChanged will PostTask to quit the message loop. 220 // OnNameOwnerChanged will PostTask to quit the message loop.
221 message_loop_.Run(); 221 message_loop_.Run();
222 // latest_name_owner_ should be empty as the owner is gone. 222 // latest_name_owner_ should be empty as the owner is gone.
223 ASSERT_TRUE(latest_name_owner_.empty()); 223 ASSERT_TRUE(latest_name_owner_.empty());
224 224
225 // Reset the flag as NameOwnerChanged is already received in setup. 225 // Reset the flag as NameOwnerChanged is already received in setup.
226 on_name_owner_changed_called_ = false; 226 on_name_owner_changed_called_ = false;
227 on_ownership_called_ = false;
227 test_service2_->RequestOwnership( 228 test_service2_->RequestOwnership(
228 base::Bind(&SignalSenderVerificationTest::OnOwnership, 229 base::Bind(&SignalSenderVerificationTest::OnOwnership,
229 base::Unretained(this), true)); 230 base::Unretained(this), true));
230 // Both of OnNameOwnerChanged() and OnOwnership() should quit the MessageLoop, 231 // Both of OnNameOwnerChanged() and OnOwnership() should quit the MessageLoop,
231 // but there's no expected order of those 2 event. 232 // but there's no expected order of those 2 event.
232 message_loop_.Run(); 233 message_loop_.Run();
233 if (!on_name_owner_changed_called_ || !on_ownership_called_) 234 if (!on_name_owner_changed_called_ || !on_ownership_called_)
234 message_loop_.Run(); 235 message_loop_.Run();
235 ASSERT_TRUE(on_name_owner_changed_called_); 236 ASSERT_TRUE(on_name_owner_changed_called_);
236 ASSERT_TRUE(on_ownership_called_); 237 ASSERT_TRUE(on_ownership_called_);
237 238
238 // latest_name_owner_ becomes non empty as the new owner appears. 239 // latest_name_owner_ becomes non empty as the new owner appears.
239 ASSERT_FALSE(latest_name_owner_.empty()); 240 ASSERT_FALSE(latest_name_owner_.empty());
240 241
241 // Now the second service owns the name. 242 // Now the second service owns the name.
242 const char kNewMessage[] = "hello, new world"; 243 const char kNewMessage[] = "hello, new world";
243 244
244 test_service2_->SendTestSignal(kNewMessage); 245 test_service2_->SendTestSignal(kNewMessage);
245 WaitForTestSignal(); 246 WaitForTestSignal();
246 ASSERT_EQ(kNewMessage, test_signal_string_); 247 ASSERT_EQ(kNewMessage, test_signal_string_);
247 } 248 }
248 249
250 TEST_F(SignalSenderVerificationTest, TestOwnerStealing) {
251 // Release and acquire the name ownership.
252 // latest_name_owner_ should be non empty as |test_service_| owns the name.
253 ASSERT_FALSE(latest_name_owner_.empty());
254 test_service_->ShutdownAndBlock();
255 // OnNameOwnerChanged will PostTask to quit the message loop.
256 message_loop_.Run();
257 // latest_name_owner_ should be empty as the owner is gone.
258 ASSERT_TRUE(latest_name_owner_.empty());
259 // Reset the flag as NameOwnerChanged is already received in setup.
260 on_name_owner_changed_called_ = false;
261
262 // Start a test service that allows theft, using the D-Bus thread.
263 TestService::Options options;
264 options.dbus_task_runner = dbus_thread_->message_loop_proxy();
265 options.request_ownership_options = Bus::REQUIRE_PRIMARY_ALLOW_REPLACEMENT;
266 TestService stealable_test_service(options);
267 ASSERT_TRUE(stealable_test_service.StartService());
268 ASSERT_TRUE(stealable_test_service.WaitUntilServiceIsStarted());
269 ASSERT_TRUE(stealable_test_service.HasDBusThread());
270 ASSERT_TRUE(stealable_test_service.has_ownership());
271
272 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.
273
274 // OnNameOwnerChanged will PostTask to quit the message loop.
275 message_loop_.Run();
276
277 // Send a signal to check that the service is correctly owned.
278 const char kMessage[] = "hello, world";
279
280 // Send the test signal from the exported object.
281 stealable_test_service.SendTestSignal(kMessage);
282 // Receive the signal with the object proxy. The signal is handled in
283 // SignalSenderVerificationTest::OnTestSignal() in the main thread.
284 WaitForTestSignal();
285 ASSERT_EQ(kMessage, test_signal_string_);
286
287 // Reset the flag as NameOwnerChanged was called above.
288 on_name_owner_changed_called_ = false;
289 test_service2_->RequestOwnership(
290 base::Bind(&SignalSenderVerificationTest::OnOwnership,
291 base::Unretained(this), true));
292 // Both of OnNameOwnerChanged() and OnOwnership() should quit the MessageLoop,
293 // but there's no expected order of those 2 event.
294 message_loop_.Run();
295 if (!on_name_owner_changed_called_ || !on_ownership_called_)
296 message_loop_.Run();
297 ASSERT_TRUE(on_name_owner_changed_called_);
298 ASSERT_TRUE(on_ownership_called_);
299
300 // Now the second service owns the name.
301 const char kNewMessage[] = "hello, new world";
302
303 test_service2_->SendTestSignal(kNewMessage);
304 WaitForTestSignal();
305 ASSERT_EQ(kNewMessage, test_signal_string_);
306 }
307
249 // Fails on Linux ChromiumOS Tests 308 // Fails on Linux ChromiumOS Tests
250 TEST_F(SignalSenderVerificationTest, DISABLED_TestMultipleObjects) { 309 TEST_F(SignalSenderVerificationTest, DISABLED_TestMultipleObjects) {
251 const char kMessage[] = "hello, world"; 310 const char kMessage[] = "hello, world";
252 311
253 ObjectProxy* object_proxy2 = bus_->GetObjectProxy( 312 ObjectProxy* object_proxy2 = bus_->GetObjectProxy(
254 "org.chromium.TestService", 313 "org.chromium.TestService",
255 ObjectPath("/org/chromium/DifferentObject")); 314 ObjectPath("/org/chromium/DifferentObject"));
256 315
257 bool second_name_owner_changed_called = false; 316 bool second_name_owner_changed_called = false;
258 object_proxy2->SetNameOwnerChangedCallback( 317 object_proxy2->SetNameOwnerChangedCallback(
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 367
309 // Now the second service owns the name. 368 // Now the second service owns the name.
310 const char kNewMessage[] = "hello, new world"; 369 const char kNewMessage[] = "hello, new world";
311 370
312 test_service2_->SendTestSignal(kNewMessage); 371 test_service2_->SendTestSignal(kNewMessage);
313 WaitForTestSignal(); 372 WaitForTestSignal();
314 ASSERT_EQ(kNewMessage, test_signal_string_); 373 ASSERT_EQ(kNewMessage, test_signal_string_);
315 } 374 }
316 375
317 } // namespace dbus 376 } // namespace dbus
OLDNEW
« dbus/bus.cc ('K') | « dbus/mock_bus.h ('k') | dbus/test_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698