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

Side by Side Diff: dbus/end_to_end_async_unittest.cc

Issue 14386016: dbus: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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
« no previous file with comments | « dbus/bus_unittest.cc ('k') | dbus/mock_unittest.cc » ('j') | 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 23 matching lines...) Expand all
34 public: 34 public:
35 EndToEndAsyncTest() : on_disconnected_call_count_(0) {} 35 EndToEndAsyncTest() : on_disconnected_call_count_(0) {}
36 36
37 virtual void SetUp() { 37 virtual void SetUp() {
38 // Make the main thread not to allow IO. 38 // Make the main thread not to allow IO.
39 base::ThreadRestrictions::SetIOAllowed(false); 39 base::ThreadRestrictions::SetIOAllowed(false);
40 40
41 // Start the D-Bus thread. 41 // Start the D-Bus thread.
42 dbus_thread_.reset(new base::Thread("D-Bus Thread")); 42 dbus_thread_.reset(new base::Thread("D-Bus Thread"));
43 base::Thread::Options thread_options; 43 base::Thread::Options thread_options;
44 thread_options.message_loop_type = MessageLoop::TYPE_IO; 44 thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
45 ASSERT_TRUE(dbus_thread_->StartWithOptions(thread_options)); 45 ASSERT_TRUE(dbus_thread_->StartWithOptions(thread_options));
46 46
47 // Start the test service, using the D-Bus thread. 47 // Start the test service, using the D-Bus thread.
48 dbus::TestService::Options options; 48 dbus::TestService::Options options;
49 options.dbus_task_runner = dbus_thread_->message_loop_proxy(); 49 options.dbus_task_runner = dbus_thread_->message_loop_proxy();
50 test_service_.reset(new dbus::TestService(options)); 50 test_service_.reset(new dbus::TestService(options));
51 ASSERT_TRUE(test_service_->StartService()); 51 ASSERT_TRUE(test_service_->StartService());
52 ASSERT_TRUE(test_service_->WaitUntilServiceIsStarted()); 52 ASSERT_TRUE(test_service_->WaitUntilServiceIsStarted());
53 ASSERT_TRUE(test_service_->HasDBusThread()); 53 ASSERT_TRUE(test_service_->HasDBusThread());
54 54
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 message_loop_.Quit(); 246 message_loop_.Quit();
247 ++on_disconnected_call_count_; 247 ++on_disconnected_call_count_;
248 } 248 }
249 249
250 // Wait for the hey signal to be received. 250 // Wait for the hey signal to be received.
251 void WaitForTestSignal() { 251 void WaitForTestSignal() {
252 // OnTestSignal() will quit the message loop. 252 // OnTestSignal() will quit the message loop.
253 message_loop_.Run(); 253 message_loop_.Run();
254 } 254 }
255 255
256 MessageLoop message_loop_; 256 base::MessageLoop message_loop_;
257 std::vector<std::string> response_strings_; 257 std::vector<std::string> response_strings_;
258 std::vector<std::string> error_names_; 258 std::vector<std::string> error_names_;
259 scoped_ptr<base::Thread> dbus_thread_; 259 scoped_ptr<base::Thread> dbus_thread_;
260 scoped_refptr<dbus::Bus> bus_; 260 scoped_refptr<dbus::Bus> bus_;
261 dbus::ObjectProxy* object_proxy_; 261 dbus::ObjectProxy* object_proxy_;
262 dbus::ObjectProxy* root_object_proxy_; 262 dbus::ObjectProxy* root_object_proxy_;
263 scoped_ptr<dbus::TestService> test_service_; 263 scoped_ptr<dbus::TestService> test_service_;
264 // Text message from "Test" signal. 264 // Text message from "Test" signal.
265 std::string test_signal_string_; 265 std::string test_signal_string_;
266 // Text message from "Test" signal delivered to root. 266 // Text message from "Test" signal delivered to root.
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 dbus::MessageWriter writer(&method_call); 530 dbus::MessageWriter writer(&method_call);
531 writer.AppendString(kHello); 531 writer.AppendString(kHello);
532 532
533 // Call the method with an empty callback. 533 // Call the method with an empty callback.
534 const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; 534 const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT;
535 object_proxy_->CallMethod(&method_call, 535 object_proxy_->CallMethod(&method_call,
536 timeout_ms, 536 timeout_ms,
537 dbus::ObjectProxy::EmptyResponseCallback()); 537 dbus::ObjectProxy::EmptyResponseCallback());
538 // Post a delayed task to quit the message loop. 538 // Post a delayed task to quit the message loop.
539 message_loop_.PostDelayedTask(FROM_HERE, 539 message_loop_.PostDelayedTask(FROM_HERE,
540 MessageLoop::QuitClosure(), 540 base::MessageLoop::QuitClosure(),
541 TestTimeouts::tiny_timeout()); 541 TestTimeouts::tiny_timeout());
542 message_loop_.Run(); 542 message_loop_.Run();
543 // We cannot tell if the empty callback is called, but at least we can 543 // We cannot tell if the empty callback is called, but at least we can
544 // check if the test does not crash. 544 // check if the test does not crash.
545 } 545 }
546 546
547 TEST_F(EndToEndAsyncTest, TestSignal) { 547 TEST_F(EndToEndAsyncTest, TestSignal) {
548 const char kMessage[] = "hello, world"; 548 const char kMessage[] = "hello, world";
549 // Send the test signal from the exported object. 549 // Send the test signal from the exported object.
550 test_service_->SendTestSignal(kMessage); 550 test_service_->SendTestSignal(kMessage);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 const char kMessage[] = "hello, world"; 635 const char kMessage[] = "hello, world";
636 // Send the test signal from the exported object. 636 // Send the test signal from the exported object.
637 test_service_->SendTestSignal(kMessage); 637 test_service_->SendTestSignal(kMessage);
638 // Receive the signal with the object proxy. 638 // Receive the signal with the object proxy.
639 WaitForTestSignal(); 639 WaitForTestSignal();
640 // Verify the string WAS received by the original handler. 640 // Verify the string WAS received by the original handler.
641 ASSERT_EQ(kMessage, test_signal_string_); 641 ASSERT_EQ(kMessage, test_signal_string_);
642 // Verify the signal WAS ALSO received by the additional handler. 642 // Verify the signal WAS ALSO received by the additional handler.
643 ASSERT_EQ(kMessage, additional_test_signal_string_); 643 ASSERT_EQ(kMessage, additional_test_signal_string_);
644 } 644 }
OLDNEW
« no previous file with comments | « dbus/bus_unittest.cc ('k') | dbus/mock_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698