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

Side by Side Diff: dbus/end_to_end_async_unittest.cc

Issue 12224139: Supporting callback for Disconnected signal. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing comments Created 7 years, 10 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
« dbus/bus.h ('K') | « dbus/bus.cc ('k') | no next file » | 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 <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 14 matching lines...) Expand all
25 // See comments in ObjectProxy::RunResponseCallback() for why the number was 25 // See comments in ObjectProxy::RunResponseCallback() for why the number was
26 // chosen. 26 // chosen.
27 const int kHugePayloadSize = 64 << 20; // 64 MB 27 const int kHugePayloadSize = 64 << 20; // 64 MB
28 28
29 } // namespace 29 } // namespace
30 30
31 // The end-to-end test exercises the asynchronous APIs in ObjectProxy and 31 // The end-to-end test exercises the asynchronous APIs in ObjectProxy and
32 // ExportedObject. 32 // ExportedObject.
33 class EndToEndAsyncTest : public testing::Test { 33 class EndToEndAsyncTest : public testing::Test {
34 public: 34 public:
35 EndToEndAsyncTest() { 35 EndToEndAsyncTest() : on_disconnected_call_count_(0) {}
36 }
37 36
38 virtual void SetUp() { 37 virtual void SetUp() {
39 // Make the main thread not to allow IO. 38 // Make the main thread not to allow IO.
40 base::ThreadRestrictions::SetIOAllowed(false); 39 base::ThreadRestrictions::SetIOAllowed(false);
41 40
42 // Start the D-Bus thread. 41 // Start the D-Bus thread.
43 dbus_thread_.reset(new base::Thread("D-Bus Thread")); 42 dbus_thread_.reset(new base::Thread("D-Bus Thread"));
44 base::Thread::Options thread_options; 43 base::Thread::Options thread_options;
45 thread_options.message_loop_type = MessageLoop::TYPE_IO; 44 thread_options.message_loop_type = MessageLoop::TYPE_IO;
46 ASSERT_TRUE(dbus_thread_->StartWithOptions(thread_options)); 45 ASSERT_TRUE(dbus_thread_->StartWithOptions(thread_options));
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 test_service_->ShutdownAndBlock(); 117 test_service_->ShutdownAndBlock();
119 118
120 // Reset to the default. 119 // Reset to the default.
121 base::ThreadRestrictions::SetIOAllowed(true); 120 base::ThreadRestrictions::SetIOAllowed(true);
122 121
123 // Stopping a thread is considered an IO operation, so do this after 122 // Stopping a thread is considered an IO operation, so do this after
124 // allowing IO. 123 // allowing IO.
125 test_service_->Stop(); 124 test_service_->Stop();
126 } 125 }
127 126
127 // Callback function which is called when the connection with dbus-daemon is
128 // disconnected.
129 void OnDisconnected() {
130 message_loop_.Quit();
131 ++on_disconnected_call_count_;
132 }
133
128 protected: 134 protected:
129 // Replaces the bus with a broken one. 135 // Replaces the bus with a broken one.
130 void SetUpBrokenBus() { 136 void SetUpBrokenBus() {
131 // Shut down the existing bus. 137 // Shut down the existing bus.
132 bus_->ShutdownOnDBusThreadAndBlock(); 138 bus_->ShutdownOnDBusThreadAndBlock();
133 139
134 // Create new bus with invalid address. 140 // Create new bus with invalid address.
135 const char kInvalidAddress[] = ""; 141 const char kInvalidAddress[] = "";
136 dbus::Bus::Options bus_options; 142 dbus::Bus::Options bus_options;
137 bus_options.bus_type = dbus::Bus::CUSTOM_ADDRESS; 143 bus_options.bus_type = dbus::Bus::CUSTOM_ADDRESS;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 std::vector<std::string> error_names_; 259 std::vector<std::string> error_names_;
254 scoped_ptr<base::Thread> dbus_thread_; 260 scoped_ptr<base::Thread> dbus_thread_;
255 scoped_refptr<dbus::Bus> bus_; 261 scoped_refptr<dbus::Bus> bus_;
256 dbus::ObjectProxy* object_proxy_; 262 dbus::ObjectProxy* object_proxy_;
257 dbus::ObjectProxy* root_object_proxy_; 263 dbus::ObjectProxy* root_object_proxy_;
258 scoped_ptr<dbus::TestService> test_service_; 264 scoped_ptr<dbus::TestService> test_service_;
259 // Text message from "Test" signal. 265 // Text message from "Test" signal.
260 std::string test_signal_string_; 266 std::string test_signal_string_;
261 // Text message from "Test" signal delivered to root. 267 // Text message from "Test" signal delivered to root.
262 std::string root_test_signal_string_; 268 std::string root_test_signal_string_;
269 int on_disconnected_call_count_;
263 }; 270 };
264 271
265 TEST_F(EndToEndAsyncTest, Echo) { 272 TEST_F(EndToEndAsyncTest, Echo) {
266 const char* kHello = "hello"; 273 const char* kHello = "hello";
267 274
268 // Create the method call. 275 // Create the method call.
269 dbus::MethodCall method_call("org.chromium.TestInterface", "Echo"); 276 dbus::MethodCall method_call("org.chromium.TestInterface", "Echo");
270 dbus::MessageWriter writer(&method_call); 277 dbus::MessageWriter writer(&method_call);
271 writer.AppendString(kHello); 278 writer.AppendString(kHello);
272 279
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 TEST_F(EndToEndAsyncTest, TestHugeSignal) { 572 TEST_F(EndToEndAsyncTest, TestHugeSignal) {
566 const std::string kHugeMessage(kHugePayloadSize, 'o'); 573 const std::string kHugeMessage(kHugePayloadSize, 'o');
567 574
568 // Send the huge signal from the exported object. 575 // Send the huge signal from the exported object.
569 test_service_->SendTestSignal(kHugeMessage); 576 test_service_->SendTestSignal(kHugeMessage);
570 // This caused a DCHECK failure before. Ensure that the issue is fixed. 577 // This caused a DCHECK failure before. Ensure that the issue is fixed.
571 WaitForTestSignal(); 578 WaitForTestSignal();
572 ASSERT_EQ(kHugeMessage, test_signal_string_); 579 ASSERT_EQ(kHugeMessage, test_signal_string_);
573 } 580 }
574 581
582 TEST_F(EndToEndAsyncTest, DisconnectedSignal) {
583 bus_->SetDisconnectedCallback(
584 base::Bind(&EndToEndAsyncTest::OnDisconnected,
585 base::Unretained(this)));
586 bus_->PostTaskToDBusThread(FROM_HERE,
587 base::Bind(&dbus::Bus::CloseConnection,
588 base::Unretained(bus_.get())));
589 // OnDisconnected callback quits message loop.
590 message_loop_.Run();
591 EXPECT_EQ(1, on_disconnected_call_count_);
592 }
593
575 class SignalReplacementTest : public EndToEndAsyncTest { 594 class SignalReplacementTest : public EndToEndAsyncTest {
576 public: 595 public:
577 SignalReplacementTest() { 596 SignalReplacementTest() {
578 } 597 }
579 598
580 virtual void SetUp() { 599 virtual void SetUp() {
581 // Set up base class. 600 // Set up base class.
582 EndToEndAsyncTest::SetUp(); 601 EndToEndAsyncTest::SetUp();
583 602
584 // Reconnect the root object proxy's signal handler to a new handler 603 // Reconnect the root object proxy's signal handler to a new handler
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 const char kMessage[] = "hello, world"; 639 const char kMessage[] = "hello, world";
621 // Send the test signal from the exported object. 640 // Send the test signal from the exported object.
622 test_service_->SendTestSignal(kMessage); 641 test_service_->SendTestSignal(kMessage);
623 // Receive the signal with the object proxy. 642 // Receive the signal with the object proxy.
624 WaitForTestSignal(); 643 WaitForTestSignal();
625 // Verify the string WAS NOT received by the original handler. 644 // Verify the string WAS NOT received by the original handler.
626 ASSERT_TRUE(test_signal_string_.empty()); 645 ASSERT_TRUE(test_signal_string_.empty());
627 // Verify the signal WAS received by the replacement handler. 646 // Verify the signal WAS received by the replacement handler.
628 ASSERT_EQ(kMessage, replacement_test_signal_string_); 647 ASSERT_EQ(kMessage, replacement_test_signal_string_);
629 } 648 }
OLDNEW
« dbus/bus.h ('K') | « dbus/bus.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698