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/shill_client_unittest_base.h" | 5 #include "chromeos/dbus/shill_client_unittest_base.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "dbus/message.h" | 10 #include "dbus/message.h" |
11 #include "dbus/object_path.h" | 11 #include "dbus/object_path.h" |
12 #include "dbus/values_util.h" | 12 #include "dbus/values_util.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "third_party/cros_system_api/dbus/service_constants.h" | 15 #include "third_party/cros_system_api/dbus/service_constants.h" |
16 | 16 |
17 using ::testing::_; | 17 using ::testing::_; |
18 using ::testing::Invoke; | 18 using ::testing::Invoke; |
19 using ::testing::Return; | 19 using ::testing::Return; |
20 | 20 |
21 namespace chromeos { | 21 namespace chromeos { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 // Runs the given task. This function is used to implement the mock bus. | |
26 void RunTask(const tracked_objects::Location& from_here, | |
27 const base::Closure& task) { | |
28 task.Run(); | |
29 } | |
30 | |
31 // Pops a string-to-string dictionary from the reader. | 25 // Pops a string-to-string dictionary from the reader. |
32 base::DictionaryValue* PopStringToStringDictionary( | 26 base::DictionaryValue* PopStringToStringDictionary( |
33 dbus::MessageReader* reader) { | 27 dbus::MessageReader* reader) { |
34 dbus::MessageReader array_reader(NULL); | 28 dbus::MessageReader array_reader(NULL); |
35 if (!reader->PopArray(&array_reader)) | 29 if (!reader->PopArray(&array_reader)) |
36 return NULL; | 30 return NULL; |
37 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); | 31 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); |
38 while (array_reader.HasMoreData()) { | 32 while (array_reader.HasMoreData()) { |
39 dbus::MessageReader entry_reader(NULL); | 33 dbus::MessageReader entry_reader(NULL); |
40 std::string key; | 34 std::string key; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 ConnectToSignal(interface_name_, shill::kMonitorPropertyChanged, _, _)) | 145 ConnectToSignal(interface_name_, shill::kMonitorPropertyChanged, _, _)) |
152 .WillRepeatedly( | 146 .WillRepeatedly( |
153 Invoke(this, &ShillClientUnittestBase::OnConnectToSignal)); | 147 Invoke(this, &ShillClientUnittestBase::OnConnectToSignal)); |
154 | 148 |
155 // Set an expectation so mock_bus's GetObjectProxy() for the given | 149 // Set an expectation so mock_bus's GetObjectProxy() for the given |
156 // service name and the object path will return mock_proxy_. | 150 // service name and the object path will return mock_proxy_. |
157 EXPECT_CALL(*mock_bus_.get(), | 151 EXPECT_CALL(*mock_bus_.get(), |
158 GetObjectProxy(shill::kFlimflamServiceName, object_path_)) | 152 GetObjectProxy(shill::kFlimflamServiceName, object_path_)) |
159 .WillOnce(Return(mock_proxy_.get())); | 153 .WillOnce(Return(mock_proxy_.get())); |
160 | 154 |
161 // Set an expectation so mock_bus's PostTaskToDBusThread() will run the | 155 // Set an expectation so mock_bus's GetDBusTaskRunner will return the current |
162 // given task. | 156 // task runner. |
163 EXPECT_CALL(*mock_bus_.get(), PostTaskToDBusThread(_, _)) | 157 EXPECT_CALL(*mock_bus_.get(), GetDBusTaskRunner()) |
164 .WillRepeatedly(Invoke(&RunTask)); | 158 .WillRepeatedly(Return(message_loop_.message_loop_proxy())); |
165 | 159 |
166 // ShutdownAndBlock() will be called in TearDown(). | 160 // ShutdownAndBlock() will be called in TearDown(). |
167 EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock()).WillOnce(Return()); | 161 EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock()).WillOnce(Return()); |
168 } | 162 } |
169 | 163 |
170 void ShillClientUnittestBase::TearDown() { | 164 void ShillClientUnittestBase::TearDown() { |
171 mock_bus_->ShutdownAndBlock(); | 165 mock_bus_->ShutdownAndBlock(); |
172 } | 166 } |
173 | 167 |
174 void ShillClientUnittestBase::PrepareForMethodCall( | 168 void ShillClientUnittestBase::PrepareForMethodCall( |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 | 382 |
389 void ShillClientUnittestBase::OnCallMethodWithErrorCallback( | 383 void ShillClientUnittestBase::OnCallMethodWithErrorCallback( |
390 dbus::MethodCall* method_call, | 384 dbus::MethodCall* method_call, |
391 int timeout_ms, | 385 int timeout_ms, |
392 const dbus::ObjectProxy::ResponseCallback& response_callback, | 386 const dbus::ObjectProxy::ResponseCallback& response_callback, |
393 const dbus::ObjectProxy::ErrorCallback& error_callback) { | 387 const dbus::ObjectProxy::ErrorCallback& error_callback) { |
394 OnCallMethod(method_call, timeout_ms, response_callback); | 388 OnCallMethod(method_call, timeout_ms, response_callback); |
395 } | 389 } |
396 | 390 |
397 } // namespace chromeos | 391 } // namespace chromeos |
OLD | NEW |