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 <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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 // Called when the response is received. | 178 // Called when the response is received. |
179 void OnResponse(dbus::Response* response) { | 179 void OnResponse(dbus::Response* response) { |
180 // |response| will be deleted on exit of the function. Copy the | 180 // |response| will be deleted on exit of the function. Copy the |
181 // payload to |response_strings_|. | 181 // payload to |response_strings_|. |
182 if (response) { | 182 if (response) { |
183 dbus::MessageReader reader(response); | 183 dbus::MessageReader reader(response); |
184 std::string response_string; | 184 std::string response_string; |
185 ASSERT_TRUE(reader.PopString(&response_string)); | 185 ASSERT_TRUE(reader.PopString(&response_string)); |
186 response_strings_.push_back(response_string); | 186 response_strings_.push_back(response_string); |
187 } else { | 187 } else { |
188 response_strings_.push_back(""); | 188 response_strings_.push_back(std::string()); |
189 } | 189 } |
190 message_loop_.Quit(); | 190 message_loop_.Quit(); |
191 }; | 191 }; |
192 | 192 |
193 // Wait for the given number of errors. | 193 // Wait for the given number of errors. |
194 void WaitForErrors(size_t num_errors) { | 194 void WaitForErrors(size_t num_errors) { |
195 while (error_names_.size() < num_errors) { | 195 while (error_names_.size() < num_errors) { |
196 message_loop_.Run(); | 196 message_loop_.Run(); |
197 } | 197 } |
198 } | 198 } |
199 | 199 |
200 // Called when an error is received. | 200 // Called when an error is received. |
201 void OnError(dbus::ErrorResponse* error) { | 201 void OnError(dbus::ErrorResponse* error) { |
202 // |error| will be deleted on exit of the function. Copy the payload to | 202 // |error| will be deleted on exit of the function. Copy the payload to |
203 // |error_names_|. | 203 // |error_names_|. |
204 if (error) { | 204 if (error) { |
205 ASSERT_NE("", error->GetErrorName()); | 205 ASSERT_NE("", error->GetErrorName()); |
206 error_names_.push_back(error->GetErrorName()); | 206 error_names_.push_back(error->GetErrorName()); |
207 } else { | 207 } else { |
208 error_names_.push_back(""); | 208 error_names_.push_back(std::string()); |
209 } | 209 } |
210 message_loop_.Quit(); | 210 message_loop_.Quit(); |
211 } | 211 } |
212 | 212 |
213 // Called when the "Test" signal is received, in the main thread. | 213 // Called when the "Test" signal is received, in the main thread. |
214 // Copy the string payload to |test_signal_string_|. | 214 // Copy the string payload to |test_signal_string_|. |
215 void OnTestSignal(dbus::Signal* signal) { | 215 void OnTestSignal(dbus::Signal* signal) { |
216 dbus::MessageReader reader(signal); | 216 dbus::MessageReader reader(signal); |
217 ASSERT_TRUE(reader.PopString(&test_signal_string_)); | 217 ASSERT_TRUE(reader.PopString(&test_signal_string_)); |
218 message_loop_.Quit(); | 218 message_loop_.Quit(); |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 NOT received by the original handler. | 640 // Verify the string WAS NOT received by the original handler. |
641 ASSERT_TRUE(test_signal_string_.empty()); | 641 ASSERT_TRUE(test_signal_string_.empty()); |
642 // Verify the signal WAS received by the replacement handler. | 642 // Verify the signal WAS received by the replacement handler. |
643 ASSERT_EQ(kMessage, replacement_test_signal_string_); | 643 ASSERT_EQ(kMessage, replacement_test_signal_string_); |
644 } | 644 } |
OLD | NEW |