OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
11 #include "dbus/mock_bus.h" | 11 #include "dbus/mock_bus.h" |
12 #include "dbus/mock_object_proxy.h" | 12 #include "dbus/mock_object_proxy.h" |
13 #include "dbus/mock_exported_object.h" | 13 #include "dbus/mock_exported_object.h" |
| 14 #include "dbus/object_path.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 using ::testing::_; | 18 using ::testing::_; |
18 using ::testing::Invoke; | 19 using ::testing::Invoke; |
19 using ::testing::Return; | 20 using ::testing::Return; |
20 using ::testing::Unused; | 21 using ::testing::Unused; |
21 | 22 |
22 class MockTest : public testing::Test { | 23 class MockTest : public testing::Test { |
23 public: | 24 public: |
(...skipping 18 matching lines...) Expand all Loading... |
42 | 43 |
43 // Set an expectation so mock_proxy's CallMethod() will use | 44 // Set an expectation so mock_proxy's CallMethod() will use |
44 // HandleMockProxyResponseWithMessageLoop() to return responses. | 45 // HandleMockProxyResponseWithMessageLoop() to return responses. |
45 EXPECT_CALL(*mock_proxy_, CallMethod(_, _, _)) | 46 EXPECT_CALL(*mock_proxy_, CallMethod(_, _, _)) |
46 .WillRepeatedly( | 47 .WillRepeatedly( |
47 Invoke(this, | 48 Invoke(this, |
48 &MockTest::HandleMockProxyResponseWithMessageLoop)); | 49 &MockTest::HandleMockProxyResponseWithMessageLoop)); |
49 | 50 |
50 // Set an expectation so mock_bus's GetObjectProxy() for the given | 51 // Set an expectation so mock_bus's GetObjectProxy() for the given |
51 // service name and the object path will return mock_proxy_. | 52 // service name and the object path will return mock_proxy_. |
52 EXPECT_CALL(*mock_bus_, GetObjectProxy("org.chromium.TestService", | 53 EXPECT_CALL(*mock_bus_, GetObjectProxy( |
53 "/org/chromium/TestObject")) | 54 "org.chromium.TestService", |
| 55 dbus::ObjectPath("/org/chromium/TestObject"))) |
54 .WillOnce(Return(mock_proxy_.get())); | 56 .WillOnce(Return(mock_proxy_.get())); |
55 | 57 |
56 // ShutdownAndBlock() will be called in TearDown(). | 58 // ShutdownAndBlock() will be called in TearDown(). |
57 EXPECT_CALL(*mock_bus_, ShutdownAndBlock()).WillOnce(Return()); | 59 EXPECT_CALL(*mock_bus_, ShutdownAndBlock()).WillOnce(Return()); |
58 } | 60 } |
59 | 61 |
60 virtual void TearDown() { | 62 virtual void TearDown() { |
61 mock_bus_->ShutdownAndBlock(); | 63 mock_bus_->ShutdownAndBlock(); |
62 } | 64 } |
63 | 65 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 // Call the method. | 171 // Call the method. |
170 proxy->CallMethod(&method_call, | 172 proxy->CallMethod(&method_call, |
171 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 173 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
172 base::Bind(&MockTest::OnResponse, | 174 base::Bind(&MockTest::OnResponse, |
173 base::Unretained(this))); | 175 base::Unretained(this))); |
174 // Run the message loop to let OnResponse be called. | 176 // Run the message loop to let OnResponse be called. |
175 message_loop_.Run(); | 177 message_loop_.Run(); |
176 | 178 |
177 EXPECT_EQ(kHello, response_string_); | 179 EXPECT_EQ(kHello, response_string_); |
178 } | 180 } |
OLD | NEW |