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/logging.h" | 6 #include "base/logging.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "dbus/message.h" | 10 #include "dbus/message.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 mock_bus_ = new dbus::MockBus(options); | 32 mock_bus_ = new dbus::MockBus(options); |
33 | 33 |
34 // Create a mock proxy. | 34 // Create a mock proxy. |
35 mock_proxy_ = new dbus::MockObjectProxy( | 35 mock_proxy_ = new dbus::MockObjectProxy( |
36 mock_bus_.get(), | 36 mock_bus_.get(), |
37 "org.chromium.TestService", | 37 "org.chromium.TestService", |
38 dbus::ObjectPath("/org/chromium/TestObject")); | 38 dbus::ObjectPath("/org/chromium/TestObject")); |
39 | 39 |
40 // Set an expectation so mock_proxy's CallMethodAndBlock() will use | 40 // Set an expectation so mock_proxy's CallMethodAndBlock() will use |
41 // CreateMockProxyResponse() to return responses. | 41 // CreateMockProxyResponse() to return responses. |
42 EXPECT_CALL(*mock_proxy_, CallMethodAndBlock(_, _)) | 42 EXPECT_CALL(*mock_proxy_, MockCallMethodAndBlock(_, _)) |
43 .WillRepeatedly(Invoke(this, &MockTest::CreateMockProxyResponse)); | 43 .WillRepeatedly(Invoke(this, &MockTest::CreateMockProxyResponse)); |
44 | 44 |
45 // Set an expectation so mock_proxy's CallMethod() will use | 45 // Set an expectation so mock_proxy's CallMethod() will use |
46 // HandleMockProxyResponseWithMessageLoop() to return responses. | 46 // HandleMockProxyResponseWithMessageLoop() to return responses. |
47 EXPECT_CALL(*mock_proxy_, CallMethod(_, _, _)) | 47 EXPECT_CALL(*mock_proxy_, CallMethod(_, _, _)) |
48 .WillRepeatedly( | 48 .WillRepeatedly( |
49 Invoke(this, | 49 Invoke(this, |
50 &MockTest::HandleMockProxyResponseWithMessageLoop)); | 50 &MockTest::HandleMockProxyResponseWithMessageLoop)); |
51 | 51 |
52 // Set an expectation so mock_bus's GetObjectProxy() for the given | 52 // Set an expectation so mock_bus's GetObjectProxy() for the given |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 private: | 84 private: |
85 // Returns a response for the given method call. Used to implement | 85 // Returns a response for the given method call. Used to implement |
86 // CallMethodAndBlock() for |mock_proxy_|. | 86 // CallMethodAndBlock() for |mock_proxy_|. |
87 dbus::Response* CreateMockProxyResponse(dbus::MethodCall* method_call, | 87 dbus::Response* CreateMockProxyResponse(dbus::MethodCall* method_call, |
88 int timeout_ms) { | 88 int timeout_ms) { |
89 if (method_call->GetInterface() == "org.chromium.TestInterface" && | 89 if (method_call->GetInterface() == "org.chromium.TestInterface" && |
90 method_call->GetMember() == "Echo") { | 90 method_call->GetMember() == "Echo") { |
91 dbus::MessageReader reader(method_call); | 91 dbus::MessageReader reader(method_call); |
92 std::string text_message; | 92 std::string text_message; |
93 if (reader.PopString(&text_message)) { | 93 if (reader.PopString(&text_message)) { |
94 dbus::Response* response = dbus::Response::CreateEmpty(); | 94 scoped_ptr<dbus::Response> response = dbus::Response::CreateEmpty(); |
95 dbus::MessageWriter writer(response); | 95 dbus::MessageWriter writer(response.get()); |
96 writer.AppendString(text_message); | 96 writer.AppendString(text_message); |
97 return response; | 97 return response.release(); |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 LOG(ERROR) << "Unexpected method call: " << method_call->ToString(); | 101 LOG(ERROR) << "Unexpected method call: " << method_call->ToString(); |
102 return NULL; | 102 return NULL; |
103 } | 103 } |
104 | 104 |
105 // Creates a response and runs the given response callback in the | 105 // Creates a response and runs the given response callback in the |
106 // message loop with the response. Used to implement for |mock_proxy_|. | 106 // message loop with the response. Used to implement for |mock_proxy_|. |
107 void HandleMockProxyResponseWithMessageLoop( | 107 void HandleMockProxyResponseWithMessageLoop( |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 // Call the method. | 172 // Call the method. |
173 proxy->CallMethod(&method_call, | 173 proxy->CallMethod(&method_call, |
174 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 174 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
175 base::Bind(&MockTest::OnResponse, | 175 base::Bind(&MockTest::OnResponse, |
176 base::Unretained(this))); | 176 base::Unretained(this))); |
177 // Run the message loop to let OnResponse be called. | 177 // Run the message loop to let OnResponse be called. |
178 message_loop_.Run(); | 178 message_loop_.Run(); |
179 | 179 |
180 EXPECT_EQ(kHello, response_string_); | 180 EXPECT_EQ(kHello, response_string_); |
181 } | 181 } |
OLD | NEW |