| 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 "chromeos/dbus/blocking_method_caller.h" | 5 #include "chromeos/dbus/blocking_method_caller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 mock_bus_ = new dbus::MockBus(options); | 53 mock_bus_ = new dbus::MockBus(options); |
| 54 | 54 |
| 55 // Create a mock proxy. | 55 // Create a mock proxy. |
| 56 mock_proxy_ = new dbus::MockObjectProxy( | 56 mock_proxy_ = new dbus::MockObjectProxy( |
| 57 mock_bus_.get(), | 57 mock_bus_.get(), |
| 58 "org.chromium.TestService", | 58 "org.chromium.TestService", |
| 59 dbus::ObjectPath("/org/chromium/TestObject")); | 59 dbus::ObjectPath("/org/chromium/TestObject")); |
| 60 | 60 |
| 61 // Set an expectation so mock_proxy's CallMethodAndBlock() will use | 61 // Set an expectation so mock_proxy's CallMethodAndBlock() will use |
| 62 // CreateMockProxyResponse() to return responses. | 62 // CreateMockProxyResponse() to return responses. |
| 63 EXPECT_CALL(*mock_proxy_.get(), MockCallMethodAndBlock(_, _)) | 63 EXPECT_CALL(*mock_proxy_.get(), |
| 64 MockCallMethodAndBlockWithErrorDetails(_, _, _)) |
| 64 .WillRepeatedly( | 65 .WillRepeatedly( |
| 65 Invoke(this, &BlockingMethodCallerTest::CreateMockProxyResponse)); | 66 Invoke(this, &BlockingMethodCallerTest::CreateMockProxyResponse)); |
| 66 | 67 |
| 67 // Set an expectation so mock_bus's GetObjectProxy() for the given | 68 // Set an expectation so mock_bus's GetObjectProxy() for the given |
| 68 // service name and the object path will return mock_proxy_. | 69 // service name and the object path will return mock_proxy_. |
| 69 EXPECT_CALL(*mock_bus_.get(), | 70 EXPECT_CALL(*mock_bus_.get(), |
| 70 GetObjectProxy("org.chromium.TestService", | 71 GetObjectProxy("org.chromium.TestService", |
| 71 dbus::ObjectPath("/org/chromium/TestObject"))) | 72 dbus::ObjectPath("/org/chromium/TestObject"))) |
| 72 .WillOnce(Return(mock_proxy_.get())); | 73 .WillOnce(Return(mock_proxy_.get())); |
| 73 | 74 |
| 74 // Set an expectation so mock_bus's GetDBusTaskRunner will return the fake | 75 // Set an expectation so mock_bus's GetDBusTaskRunner will return the fake |
| 75 // task runner. | 76 // task runner. |
| 76 EXPECT_CALL(*mock_bus_.get(), GetDBusTaskRunner()) | 77 EXPECT_CALL(*mock_bus_.get(), GetDBusTaskRunner()) |
| 77 .WillRepeatedly(Return(task_runner_.get())); | 78 .WillRepeatedly(Return(task_runner_.get())); |
| 78 | 79 |
| 79 // ShutdownAndBlock() will be called in TearDown(). | 80 // ShutdownAndBlock() will be called in TearDown(). |
| 80 EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock()).WillOnce(Return()); | 81 EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock()).WillOnce(Return()); |
| 81 } | 82 } |
| 82 | 83 |
| 83 void TearDown() override { mock_bus_->ShutdownAndBlock(); } | 84 void TearDown() override { mock_bus_->ShutdownAndBlock(); } |
| 84 | 85 |
| 85 protected: | 86 protected: |
| 86 scoped_refptr<FakeTaskRunner> task_runner_; | 87 scoped_refptr<FakeTaskRunner> task_runner_; |
| 87 scoped_refptr<dbus::MockBus> mock_bus_; | 88 scoped_refptr<dbus::MockBus> mock_bus_; |
| 88 scoped_refptr<dbus::MockObjectProxy> mock_proxy_; | 89 scoped_refptr<dbus::MockObjectProxy> mock_proxy_; |
| 89 | 90 |
| 90 private: | 91 private: |
| 91 // Returns a response for the given method call. Used to implement | 92 // Returns a response for the given method call. Used to implement |
| 92 // CallMethodAndBlock() for |mock_proxy_|. | 93 // CallMethodAndBlock() for |mock_proxy_|. |
| 93 dbus::Response* CreateMockProxyResponse(dbus::MethodCall* method_call, | 94 dbus::Response* CreateMockProxyResponse(dbus::MethodCall* method_call, |
| 94 int timeout_ms) { | 95 int timeout_ms, |
| 96 dbus::ScopedDBusError* error) { |
| 95 if (method_call->GetInterface() == "org.chromium.TestInterface" && | 97 if (method_call->GetInterface() == "org.chromium.TestInterface" && |
| 96 method_call->GetMember() == "Echo") { | 98 method_call->GetMember() == "Echo") { |
| 97 dbus::MessageReader reader(method_call); | 99 dbus::MessageReader reader(method_call); |
| 98 std::string text_message; | 100 std::string text_message; |
| 99 if (reader.PopString(&text_message)) { | 101 if (reader.PopString(&text_message)) { |
| 100 std::unique_ptr<dbus::Response> response = | 102 std::unique_ptr<dbus::Response> response = |
| 101 dbus::Response::CreateEmpty(); | 103 dbus::Response::CreateEmpty(); |
| 102 dbus::MessageWriter writer(response.get()); | 104 dbus::MessageWriter writer(response.get()); |
| 103 writer.AppendString(text_message); | 105 writer.AppendString(text_message); |
| 104 return response.release(); | 106 return response.release(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 130 // Check the response. | 132 // Check the response. |
| 131 ASSERT_TRUE(response.get()); | 133 ASSERT_TRUE(response.get()); |
| 132 dbus::MessageReader reader(response.get()); | 134 dbus::MessageReader reader(response.get()); |
| 133 std::string text_message; | 135 std::string text_message; |
| 134 ASSERT_TRUE(reader.PopString(&text_message)); | 136 ASSERT_TRUE(reader.PopString(&text_message)); |
| 135 // The text message should be echo'ed back. | 137 // The text message should be echo'ed back. |
| 136 EXPECT_EQ(kHello, text_message); | 138 EXPECT_EQ(kHello, text_message); |
| 137 } | 139 } |
| 138 | 140 |
| 139 } // namespace chromeos | 141 } // namespace chromeos |
| OLD | NEW |