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 <memory> |
| 6 |
5 #include "base/bind.h" | 7 #include "base/bind.h" |
6 #include "base/memory/scoped_ptr.h" | |
7 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
8 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
9 #include "base/metrics/histogram_samples.h" | 10 #include "base/metrics/histogram_samples.h" |
10 #include "base/metrics/statistics_recorder.h" | 11 #include "base/metrics/statistics_recorder.h" |
11 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
12 #include "base/test/test_timeouts.h" | 13 #include "base/test/test_timeouts.h" |
13 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
14 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
15 #include "dbus/bus.h" | 16 #include "dbus/bus.h" |
16 #include "dbus/message.h" | 17 #include "dbus/message.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 162 |
162 // Stopping a thread is considered an IO operation, so we need to fiddle with | 163 // Stopping a thread is considered an IO operation, so we need to fiddle with |
163 // thread restrictions before and after calling Stop() on a TestService. | 164 // thread restrictions before and after calling Stop() on a TestService. |
164 void SafeServiceStop(TestService* test_service) { | 165 void SafeServiceStop(TestService* test_service) { |
165 base::ThreadRestrictions::SetIOAllowed(true); | 166 base::ThreadRestrictions::SetIOAllowed(true); |
166 test_service->Stop(); | 167 test_service->Stop(); |
167 base::ThreadRestrictions::SetIOAllowed(false); | 168 base::ThreadRestrictions::SetIOAllowed(false); |
168 } | 169 } |
169 | 170 |
170 base::MessageLoop message_loop_; | 171 base::MessageLoop message_loop_; |
171 scoped_ptr<base::RunLoop> run_loop_; | 172 std::unique_ptr<base::RunLoop> run_loop_; |
172 scoped_ptr<base::Thread> dbus_thread_; | 173 std::unique_ptr<base::Thread> dbus_thread_; |
173 scoped_refptr<Bus> bus_; | 174 scoped_refptr<Bus> bus_; |
174 ObjectProxy* object_proxy_; | 175 ObjectProxy* object_proxy_; |
175 scoped_ptr<TestService> test_service_; | 176 std::unique_ptr<TestService> test_service_; |
176 scoped_ptr<TestService> test_service2_; | 177 std::unique_ptr<TestService> test_service2_; |
177 // Text message from "Test" signal. | 178 // Text message from "Test" signal. |
178 std::string test_signal_string_; | 179 std::string test_signal_string_; |
179 | 180 |
180 // The known latest name owner of TestService. Updated in OnNameOwnerChanged. | 181 // The known latest name owner of TestService. Updated in OnNameOwnerChanged. |
181 std::string latest_name_owner_; | 182 std::string latest_name_owner_; |
182 | 183 |
183 // Boolean flags to record callback calls. | 184 // Boolean flags to record callback calls. |
184 bool on_name_owner_changed_called_; | 185 bool on_name_owner_changed_called_; |
185 bool on_ownership_called_; | 186 bool on_ownership_called_; |
186 }; | 187 }; |
187 | 188 |
188 TEST_F(SignalSenderVerificationTest, TestSignalAccepted) { | 189 TEST_F(SignalSenderVerificationTest, TestSignalAccepted) { |
189 const char kMessage[] = "hello, world"; | 190 const char kMessage[] = "hello, world"; |
190 // Send the test signal from the exported object. | 191 // Send the test signal from the exported object. |
191 test_service_->SendTestSignal(kMessage); | 192 test_service_->SendTestSignal(kMessage); |
192 // Receive the signal with the object proxy. The signal is handled in | 193 // Receive the signal with the object proxy. The signal is handled in |
193 // SignalSenderVerificationTest::OnTestSignal() in the main thread. | 194 // SignalSenderVerificationTest::OnTestSignal() in the main thread. |
194 WaitForTestSignal(); | 195 WaitForTestSignal(); |
195 ASSERT_EQ(kMessage, test_signal_string_); | 196 ASSERT_EQ(kMessage, test_signal_string_); |
196 } | 197 } |
197 | 198 |
198 // Disabled, http://crbug.com/407063 . | 199 // Disabled, http://crbug.com/407063 . |
199 TEST_F(SignalSenderVerificationTest, DISABLED_TestSignalRejected) { | 200 TEST_F(SignalSenderVerificationTest, DISABLED_TestSignalRejected) { |
200 // To make sure the histogram instance is created. | 201 // To make sure the histogram instance is created. |
201 UMA_HISTOGRAM_COUNTS("DBus.RejectedSignalCount", 0); | 202 UMA_HISTOGRAM_COUNTS("DBus.RejectedSignalCount", 0); |
202 base::HistogramBase* reject_signal_histogram = | 203 base::HistogramBase* reject_signal_histogram = |
203 base::StatisticsRecorder::FindHistogram("DBus.RejectedSignalCount"); | 204 base::StatisticsRecorder::FindHistogram("DBus.RejectedSignalCount"); |
204 scoped_ptr<base::HistogramSamples> samples1( | 205 std::unique_ptr<base::HistogramSamples> samples1( |
205 reject_signal_histogram->SnapshotSamples()); | 206 reject_signal_histogram->SnapshotSamples()); |
206 | 207 |
207 const char kNewMessage[] = "hello, new world"; | 208 const char kNewMessage[] = "hello, new world"; |
208 test_service2_->SendTestSignal(kNewMessage); | 209 test_service2_->SendTestSignal(kNewMessage); |
209 | 210 |
210 // This test tests that our callback is NOT called by the ObjectProxy. | 211 // This test tests that our callback is NOT called by the ObjectProxy. |
211 // Sleep to have message delivered to the client via the D-Bus service. | 212 // Sleep to have message delivered to the client via the D-Bus service. |
212 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); | 213 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); |
213 | 214 |
214 scoped_ptr<base::HistogramSamples> samples2( | 215 std::unique_ptr<base::HistogramSamples> samples2( |
215 reject_signal_histogram->SnapshotSamples()); | 216 reject_signal_histogram->SnapshotSamples()); |
216 | 217 |
217 ASSERT_EQ("", test_signal_string_); | 218 ASSERT_EQ("", test_signal_string_); |
218 EXPECT_EQ(samples1->TotalCount() + 1, samples2->TotalCount()); | 219 EXPECT_EQ(samples1->TotalCount() + 1, samples2->TotalCount()); |
219 } | 220 } |
220 | 221 |
221 TEST_F(SignalSenderVerificationTest, TestOwnerChanged) { | 222 TEST_F(SignalSenderVerificationTest, TestOwnerChanged) { |
222 const char kMessage[] = "hello, world"; | 223 const char kMessage[] = "hello, world"; |
223 | 224 |
224 // Send the test signal from the exported object. | 225 // Send the test signal from the exported object. |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 | 397 |
397 // Now the second service owns the name. | 398 // Now the second service owns the name. |
398 const char kNewMessage[] = "hello, new world"; | 399 const char kNewMessage[] = "hello, new world"; |
399 | 400 |
400 test_service2_->SendTestSignal(kNewMessage); | 401 test_service2_->SendTestSignal(kNewMessage); |
401 WaitForTestSignal(); | 402 WaitForTestSignal(); |
402 ASSERT_EQ(kNewMessage, test_signal_string_); | 403 ASSERT_EQ(kNewMessage, test_signal_string_); |
403 } | 404 } |
404 | 405 |
405 } // namespace dbus | 406 } // namespace dbus |
OLD | NEW |