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 23 matching lines...) Expand all Loading... |
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 = 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_thread_message_loop_proxy = | 44 bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy(); |
45 dbus_thread_->message_loop_proxy(); | |
46 bus_ = new dbus::Bus(bus_options); | 45 bus_ = new dbus::Bus(bus_options); |
47 object_proxy_ = bus_->GetObjectProxy( | 46 object_proxy_ = bus_->GetObjectProxy( |
48 "org.chromium.TestService", | 47 "org.chromium.TestService", |
49 dbus::ObjectPath("/org/chromium/TestObject")); | 48 dbus::ObjectPath("/org/chromium/TestObject")); |
50 ASSERT_TRUE(bus_->HasDBusThread()); | 49 ASSERT_TRUE(bus_->HasDBusThread()); |
51 | 50 |
52 object_proxy_->SetNameOwnerChangedCallback( | 51 object_proxy_->SetNameOwnerChangedCallback( |
53 base::Bind(&SignalSenderVerificationTest::OnNameOwnerChanged, | 52 base::Bind(&SignalSenderVerificationTest::OnNameOwnerChanged, |
54 base::Unretained(this), | 53 base::Unretained(this), |
55 &on_name_owner_changed_called_)); | 54 &on_name_owner_changed_called_)); |
56 | 55 |
57 // Connect to the "Test" signal of "org.chromium.TestInterface" from | 56 // Connect to the "Test" signal of "org.chromium.TestInterface" from |
58 // the remote object. | 57 // the remote object. |
59 object_proxy_->ConnectToSignal( | 58 object_proxy_->ConnectToSignal( |
60 "org.chromium.TestInterface", | 59 "org.chromium.TestInterface", |
61 "Test", | 60 "Test", |
62 base::Bind(&SignalSenderVerificationTest::OnTestSignal, | 61 base::Bind(&SignalSenderVerificationTest::OnTestSignal, |
63 base::Unretained(this)), | 62 base::Unretained(this)), |
64 base::Bind(&SignalSenderVerificationTest::OnConnected, | 63 base::Bind(&SignalSenderVerificationTest::OnConnected, |
65 base::Unretained(this))); | 64 base::Unretained(this))); |
66 // Wait until the object proxy is connected to the signal. | 65 // Wait until the object proxy is connected to the signal. |
67 message_loop_.Run(); | 66 message_loop_.Run(); |
68 | 67 |
69 // Start the test service, using the D-Bus thread. | 68 // Start the test service, using the D-Bus thread. |
70 dbus::TestService::Options options; | 69 dbus::TestService::Options options; |
71 options.dbus_thread_message_loop_proxy = dbus_thread_->message_loop_proxy(); | 70 options.dbus_task_runner = dbus_thread_->message_loop_proxy(); |
72 test_service_.reset(new dbus::TestService(options)); | 71 test_service_.reset(new dbus::TestService(options)); |
73 ASSERT_TRUE(test_service_->StartService()); | 72 ASSERT_TRUE(test_service_->StartService()); |
74 ASSERT_TRUE(test_service_->WaitUntilServiceIsStarted()); | 73 ASSERT_TRUE(test_service_->WaitUntilServiceIsStarted()); |
75 ASSERT_TRUE(test_service_->HasDBusThread()); | 74 ASSERT_TRUE(test_service_->HasDBusThread()); |
76 ASSERT_TRUE(test_service_->has_ownership()); | 75 ASSERT_TRUE(test_service_->has_ownership()); |
77 | 76 |
78 // Same setup for the second TestService. This service should not have the | 77 // Same setup for the second TestService. This service should not have the |
79 // ownership of the name at this point. | 78 // ownership of the name at this point. |
80 test_service2_.reset(new dbus::TestService(options)); | 79 test_service2_.reset(new dbus::TestService(options)); |
81 ASSERT_TRUE(test_service2_->StartService()); | 80 ASSERT_TRUE(test_service2_->StartService()); |
82 ASSERT_TRUE(test_service2_->WaitUntilServiceIsStarted()); | 81 ASSERT_TRUE(test_service2_->WaitUntilServiceIsStarted()); |
83 ASSERT_TRUE(test_service2_->HasDBusThread()); | 82 ASSERT_TRUE(test_service2_->HasDBusThread()); |
84 ASSERT_FALSE(test_service2_->has_ownership()); | 83 ASSERT_FALSE(test_service2_->has_ownership()); |
85 | 84 |
86 // The name should be owned and known at this point. | 85 // The name should be owned and known at this point. |
87 if (!on_name_owner_changed_called_) | 86 if (!on_name_owner_changed_called_) |
88 message_loop_.Run(); | 87 message_loop_.Run(); |
89 ASSERT_FALSE(latest_name_owner_.empty()); | 88 ASSERT_FALSE(latest_name_owner_.empty()); |
90 | |
91 } | 89 } |
92 | 90 |
93 virtual void TearDown() { | 91 virtual void TearDown() { |
94 bus_->ShutdownOnDBusThreadAndBlock(); | 92 bus_->ShutdownOnDBusThreadAndBlock(); |
95 | 93 |
96 // Shut down the service. | 94 // Shut down the service. |
97 test_service_->ShutdownAndBlock(); | 95 test_service_->ShutdownAndBlock(); |
98 test_service2_->ShutdownAndBlock(); | 96 test_service2_->ShutdownAndBlock(); |
99 | 97 |
100 // Reset to the default. | 98 // Reset to the default. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 139 |
142 // Called when connected to the signal. | 140 // Called when connected to the signal. |
143 void OnConnected(const std::string& interface_name, | 141 void OnConnected(const std::string& interface_name, |
144 const std::string& signal_name, | 142 const std::string& signal_name, |
145 bool success) { | 143 bool success) { |
146 ASSERT_TRUE(success); | 144 ASSERT_TRUE(success); |
147 message_loop_.Quit(); | 145 message_loop_.Quit(); |
148 } | 146 } |
149 | 147 |
150 protected: | 148 protected: |
151 | |
152 // Wait for the hey signal to be received. | 149 // Wait for the hey signal to be received. |
153 void WaitForTestSignal() { | 150 void WaitForTestSignal() { |
154 // OnTestSignal() will quit the message loop. | 151 // OnTestSignal() will quit the message loop. |
155 message_loop_.Run(); | 152 message_loop_.Run(); |
156 } | 153 } |
157 | 154 |
158 MessageLoop message_loop_; | 155 MessageLoop message_loop_; |
159 scoped_ptr<base::Thread> dbus_thread_; | 156 scoped_ptr<base::Thread> dbus_thread_; |
160 scoped_refptr<dbus::Bus> bus_; | 157 scoped_refptr<dbus::Bus> bus_; |
161 dbus::ObjectProxy* object_proxy_; | 158 dbus::ObjectProxy* object_proxy_; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 // latest_name_owner_ becomes non empty as the new owner appears. | 304 // latest_name_owner_ becomes non empty as the new owner appears. |
308 ASSERT_FALSE(latest_name_owner_.empty()); | 305 ASSERT_FALSE(latest_name_owner_.empty()); |
309 | 306 |
310 // Now the second service owns the name. | 307 // Now the second service owns the name. |
311 const char kNewMessage[] = "hello, new world"; | 308 const char kNewMessage[] = "hello, new world"; |
312 | 309 |
313 test_service2_->SendTestSignal(kNewMessage); | 310 test_service2_->SendTestSignal(kNewMessage); |
314 WaitForTestSignal(); | 311 WaitForTestSignal(); |
315 ASSERT_EQ(kNewMessage, test_signal_string_); | 312 ASSERT_EQ(kNewMessage, test_signal_string_); |
316 } | 313 } |
OLD | NEW |