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.h" | 7 #include "base/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 16 matching lines...) Expand all Loading... |
27 | 27 |
28 virtual void SetUp() { | 28 virtual void SetUp() { |
29 base::StatisticsRecorder::Initialize(); | 29 base::StatisticsRecorder::Initialize(); |
30 | 30 |
31 // Make the main thread not to allow IO. | 31 // Make the main thread not to allow IO. |
32 base::ThreadRestrictions::SetIOAllowed(false); | 32 base::ThreadRestrictions::SetIOAllowed(false); |
33 | 33 |
34 // Start the D-Bus thread. | 34 // Start the D-Bus thread. |
35 dbus_thread_.reset(new base::Thread("D-Bus Thread")); | 35 dbus_thread_.reset(new base::Thread("D-Bus Thread")); |
36 base::Thread::Options thread_options; | 36 base::Thread::Options thread_options; |
37 thread_options.message_loop_type = MessageLoop::TYPE_IO; | 37 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; |
38 ASSERT_TRUE(dbus_thread_->StartWithOptions(thread_options)); | 38 ASSERT_TRUE(dbus_thread_->StartWithOptions(thread_options)); |
39 | 39 |
40 // Create the client, using the D-Bus thread. | 40 // Create the client, using the D-Bus thread. |
41 dbus::Bus::Options bus_options; | 41 dbus::Bus::Options bus_options; |
42 bus_options.bus_type = dbus::Bus::SESSION; | 42 bus_options.bus_type = dbus::Bus::SESSION; |
43 bus_options.connection_type = dbus::Bus::PRIVATE; | 43 bus_options.connection_type = dbus::Bus::PRIVATE; |
44 bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy(); | 44 bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy(); |
45 bus_ = new dbus::Bus(bus_options); | 45 bus_ = new dbus::Bus(bus_options); |
46 object_proxy_ = bus_->GetObjectProxy( | 46 object_proxy_ = bus_->GetObjectProxy( |
47 "org.chromium.TestService", | 47 "org.chromium.TestService", |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 message_loop_.Quit(); | 145 message_loop_.Quit(); |
146 } | 146 } |
147 | 147 |
148 protected: | 148 protected: |
149 // Wait for the hey signal to be received. | 149 // Wait for the hey signal to be received. |
150 void WaitForTestSignal() { | 150 void WaitForTestSignal() { |
151 // OnTestSignal() will quit the message loop. | 151 // OnTestSignal() will quit the message loop. |
152 message_loop_.Run(); | 152 message_loop_.Run(); |
153 } | 153 } |
154 | 154 |
155 MessageLoop message_loop_; | 155 base::MessageLoop message_loop_; |
156 scoped_ptr<base::Thread> dbus_thread_; | 156 scoped_ptr<base::Thread> dbus_thread_; |
157 scoped_refptr<dbus::Bus> bus_; | 157 scoped_refptr<dbus::Bus> bus_; |
158 dbus::ObjectProxy* object_proxy_; | 158 dbus::ObjectProxy* object_proxy_; |
159 scoped_ptr<dbus::TestService> test_service_; | 159 scoped_ptr<dbus::TestService> test_service_; |
160 scoped_ptr<dbus::TestService> test_service2_; | 160 scoped_ptr<dbus::TestService> test_service2_; |
161 // Text message from "Test" signal. | 161 // Text message from "Test" signal. |
162 std::string test_signal_string_; | 162 std::string test_signal_string_; |
163 | 163 |
164 // The known latest name owner of TestService. Updated in OnNameOwnerChanged. | 164 // The known latest name owner of TestService. Updated in OnNameOwnerChanged. |
165 std::string latest_name_owner_; | 165 std::string latest_name_owner_; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 // latest_name_owner_ becomes non empty as the new owner appears. | 304 // latest_name_owner_ becomes non empty as the new owner appears. |
305 ASSERT_FALSE(latest_name_owner_.empty()); | 305 ASSERT_FALSE(latest_name_owner_.empty()); |
306 | 306 |
307 // Now the second service owns the name. | 307 // Now the second service owns the name. |
308 const char kNewMessage[] = "hello, new world"; | 308 const char kNewMessage[] = "hello, new world"; |
309 | 309 |
310 test_service2_->SendTestSignal(kNewMessage); | 310 test_service2_->SendTestSignal(kNewMessage); |
311 WaitForTestSignal(); | 311 WaitForTestSignal(); |
312 ASSERT_EQ(kNewMessage, test_signal_string_); | 312 ASSERT_EQ(kNewMessage, test_signal_string_); |
313 } | 313 } |
OLD | NEW |