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

Unified Diff: chrome/browser/chromeos/dbus/proxy_resolution_service_provider_unittest.cc

Issue 8728020: chrome: dbus: support asynchronous method replies (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comment Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/dbus/proxy_resolution_service_provider.cc ('k') | dbus/bus.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/dbus/proxy_resolution_service_provider_unittest.cc
diff --git a/chrome/browser/chromeos/dbus/proxy_resolution_service_provider_unittest.cc b/chrome/browser/chromeos/dbus/proxy_resolution_service_provider_unittest.cc
index 93b2781a2c6cf8db0e7dbdc2016e477cb0aa990a..bbd2a4d685626d69aa85dab195bb3ac80de60e38 100644
--- a/chrome/browser/chromeos/dbus/proxy_resolution_service_provider_unittest.cc
+++ b/chrome/browser/chromeos/dbus/proxy_resolution_service_provider_unittest.cc
@@ -17,6 +17,7 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
+#include "base/message_loop.h"
#include "dbus/message.h"
#include "dbus/mock_bus.h"
#include "dbus/mock_exported_object.h"
@@ -61,7 +62,8 @@ class ProxyResolutionServiceProviderTest : public testing::Test {
public:
ProxyResolutionServiceProviderTest()
: signal_received_successfully_(false),
- mock_resolver_(NULL) {
+ mock_resolver_(NULL),
+ response_received_(false) {
}
virtual void SetUp() {
@@ -102,12 +104,12 @@ class ProxyResolutionServiceProviderTest : public testing::Test {
kLibCrosServiceName,
kLibCrosServicePath);
// |mock_object_proxy_|'s CallMethodAndBlock() will use
- // CreateResponse() to return responses.
+ // MockCallMethodAndBlock() to return responses.
EXPECT_CALL(*mock_object_proxy_,
CallMethodAndBlock(_, _))
.WillOnce(Invoke(
this,
- &ProxyResolutionServiceProviderTest::CreateResponse));
+ &ProxyResolutionServiceProviderTest::MockCallMethodAndBlock));
// |mock_object_proxy_|'s ConnectToSignal will use
// MockConnectToSignal().
EXPECT_CALL(*mock_object_proxy_,
@@ -185,6 +187,9 @@ class ProxyResolutionServiceProviderTest : public testing::Test {
scoped_ptr<ProxyResolutionServiceProvider> proxy_resolution_service_;
dbus::ExportedObject::MethodCallCallback resolve_network_proxy_;
dbus::ObjectProxy::SignalCallback on_signal_callback_;
+ MessageLoop message_loop_;
+ bool response_received_;
+ scoped_ptr<dbus::Response> response_;
private:
// Behaves as |mock_exported_object_|'s ExportMethod().
@@ -237,24 +242,40 @@ class ProxyResolutionServiceProviderTest : public testing::Test {
LOG(ERROR) << "Unexpected source URL: " << source_url;
}
- // Creates a response for |mock_object_proxy_|.
- dbus::Response* CreateResponse(
+ // Calls exported method and waits for a response for |mock_object_proxy_|.
+ dbus::Response* MockCallMethodAndBlock(
dbus::MethodCall* method_call,
Unused) {
- if (method_call->GetInterface() ==
- kLibCrosServiceInterface &&
- method_call->GetMember() == kResolveNetworkProxy) {
- // Set the serial number to non-zero, so
- // dbus_message_new_method_return() won't emit a warning.
- method_call->SetSerial(1);
- // Run the callback captured in MockExportMethod(). This will send
- // a signal, which will be received by |on_signal_callback_|.
- dbus::Response* response = resolve_network_proxy_.Run(method_call);
- return response;
+ if (method_call->GetInterface() != kLibCrosServiceInterface ||
+ method_call->GetMember() != kResolveNetworkProxy) {
+ LOG(ERROR) << "Unexpected method call: " << method_call->ToString();
+ return NULL;
}
+ // Set the serial number to non-zero, so
+ // dbus_message_new_method_return() won't emit a warning.
+ method_call->SetSerial(1);
+ // Run the callback captured in MockExportMethod(). In addition to returning
+ // a response that the caller will ignore, this will send a signal, which
+ // will be received by |on_signal_callback_|.
+ resolve_network_proxy_.Run(
+ method_call,
+ base::Bind(&ProxyResolutionServiceProviderTest::OnResponse,
+ base::Unretained(this)));
+ // Wait for a response.
+ while (!response_received_) {
+ message_loop_.Run();
Paweł Hajdan Jr. 2011/11/30 08:46:11 This is generally an anti-pattern. Could you only
Vince Laviano 2011/11/30 23:47:48 http://codereview.chromium.org/8764006/
+ }
+ // Return response.
+ return response_.release();
+ }
- LOG(ERROR) << "Unexpected method call: " << method_call->ToString();
- return NULL;
+ // Receives a response and makes it available to MockCallMethodAndBlock().
+ void OnResponse(dbus::Response* response) {
+ response_.reset(response);
+ response_received_ = true;
+ if (message_loop_.is_running()) {
+ message_loop_.Quit();
+ }
}
// Behaves as |mock_object_proxy_|'s ConnectToSignal().
« no previous file with comments | « chrome/browser/chromeos/dbus/proxy_resolution_service_provider.cc ('k') | dbus/bus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698