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 <algorithm> | 5 #include <algorithm> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 // arrives from a different object path like "/" the first object proxy | 336 // arrives from a different object path like "/" the first object proxy |
337 // |object_proxy_| should not handle it, and should leave it for the root | 337 // |object_proxy_| should not handle it, and should leave it for the root |
338 // object proxy |root_object_proxy_|. | 338 // object proxy |root_object_proxy_|. |
339 test_service_->SendTestSignalFromRoot(kMessage); | 339 test_service_->SendTestSignalFromRoot(kMessage); |
340 WaitForTestSignal(); | 340 WaitForTestSignal(); |
341 // Verify the signal was not received by the specific proxy. | 341 // Verify the signal was not received by the specific proxy. |
342 ASSERT_TRUE(test_signal_string_.empty()); | 342 ASSERT_TRUE(test_signal_string_.empty()); |
343 // Verify the string WAS received by the root proxy. | 343 // Verify the string WAS received by the root proxy. |
344 ASSERT_EQ(kMessage, root_test_signal_string_); | 344 ASSERT_EQ(kMessage, root_test_signal_string_); |
345 } | 345 } |
| 346 |
| 347 class SignalReplacementTest : public EndToEndAsyncTest { |
| 348 public: |
| 349 SignalReplacementTest() { |
| 350 } |
| 351 |
| 352 virtual void SetUp() { |
| 353 // Set up base class. |
| 354 EndToEndAsyncTest::SetUp(); |
| 355 |
| 356 // Reconnect the root object proxy's signal handler to a new handler |
| 357 // so that we can verify that a second call to ConnectSignal() delivers |
| 358 // to our new handler and not the old. |
| 359 object_proxy_->ConnectToSignal( |
| 360 "org.chromium.TestInterface", |
| 361 "Test", |
| 362 base::Bind(&SignalReplacementTest::OnReplacementTestSignal, |
| 363 base::Unretained(this)), |
| 364 base::Bind(&SignalReplacementTest::OnReplacementConnected, |
| 365 base::Unretained(this))); |
| 366 // Wait until the object proxy is connected to the signal. |
| 367 message_loop_.Run(); |
| 368 } |
| 369 |
| 370 protected: |
| 371 // Called when the "Test" signal is received, in the main thread. |
| 372 // Copy the string payload to |replacement_test_signal_string_|. |
| 373 void OnReplacementTestSignal(dbus::Signal* signal) { |
| 374 dbus::MessageReader reader(signal); |
| 375 ASSERT_TRUE(reader.PopString(&replacement_test_signal_string_)); |
| 376 message_loop_.Quit(); |
| 377 } |
| 378 |
| 379 // Called when connected to the signal. |
| 380 void OnReplacementConnected(const std::string& interface_name, |
| 381 const std::string& signal_name, |
| 382 bool success) { |
| 383 ASSERT_TRUE(success); |
| 384 message_loop_.Quit(); |
| 385 } |
| 386 |
| 387 // Text message from "Test" signal delivered to replacement handler. |
| 388 std::string replacement_test_signal_string_; |
| 389 }; |
| 390 |
| 391 TEST_F(SignalReplacementTest, TestSignalReplacement) { |
| 392 const char kMessage[] = "hello, world"; |
| 393 // Send the test signal from the exported object. |
| 394 test_service_->SendTestSignal(kMessage); |
| 395 // Receive the signal with the object proxy. |
| 396 WaitForTestSignal(); |
| 397 // Verify the string WAS NOT received by the original handler. |
| 398 ASSERT_TRUE(test_signal_string_.empty()); |
| 399 // Verify the signal WAS received by the replacement handler. |
| 400 ASSERT_EQ(kMessage, replacement_test_signal_string_); |
| 401 } |
OLD | NEW |