| 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/values.h" | 6 #include "base/values.h" |
| 7 #include "chromeos/dbus/shill_client_unittest_base.h" | 7 #include "chromeos/dbus/shill_client_unittest_base.h" |
| 8 #include "chromeos/dbus/shill_service_client.h" | 8 #include "chromeos/dbus/shill_service_client.h" |
| 9 #include "dbus/message.h" | 9 #include "dbus/message.h" |
| 10 #include "dbus/object_path.h" | 10 #include "dbus/object_path.h" |
| 11 #include "dbus/values_util.h" | 11 #include "dbus/values_util.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "third_party/cros_system_api/dbus/service_constants.h" | 13 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 14 | 14 |
| 15 using testing::_; |
| 16 using testing::ByRef; |
| 17 |
| 15 namespace chromeos { | 18 namespace chromeos { |
| 16 | 19 |
| 17 namespace { | 20 namespace { |
| 18 | 21 |
| 19 const char kExampleServicePath[] = "/foo/bar"; | 22 const char kExampleServicePath[] = "/foo/bar"; |
| 20 | 23 |
| 21 } // namespace | 24 } // namespace |
| 22 | 25 |
| 23 class ShillServiceClientTest : public ShillClientUnittestBase { | 26 class ShillServiceClientTest : public ShillClientUnittestBase { |
| 24 public: | 27 public: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 48 const int kValue = 42; | 51 const int kValue = 42; |
| 49 // Create a signal. | 52 // Create a signal. |
| 50 dbus::Signal signal(flimflam::kFlimflamServiceInterface, | 53 dbus::Signal signal(flimflam::kFlimflamServiceInterface, |
| 51 flimflam::kMonitorPropertyChanged); | 54 flimflam::kMonitorPropertyChanged); |
| 52 dbus::MessageWriter writer(&signal); | 55 dbus::MessageWriter writer(&signal); |
| 53 writer.AppendString(flimflam::kSignalStrengthProperty); | 56 writer.AppendString(flimflam::kSignalStrengthProperty); |
| 54 writer.AppendVariantOfByte(kValue); | 57 writer.AppendVariantOfByte(kValue); |
| 55 | 58 |
| 56 // Set expectations. | 59 // Set expectations. |
| 57 const base::FundamentalValue value(kValue); | 60 const base::FundamentalValue value(kValue); |
| 58 client_->SetPropertyChangedHandler( | 61 MockPropertyChangeObserver observer; |
| 62 EXPECT_CALL(observer, |
| 63 OnPropertyChanged( |
| 64 flimflam::kSignalStrengthProperty, |
| 65 ValueEq(ByRef(value)))).Times(1); |
| 66 |
| 67 // Add the observer |
| 68 client_->AddPropertyChangedObserver( |
| 59 dbus::ObjectPath(kExampleServicePath), | 69 dbus::ObjectPath(kExampleServicePath), |
| 60 base::Bind(&ExpectPropertyChanged, | 70 &observer); |
| 61 flimflam::kSignalStrengthProperty, | 71 |
| 62 &value)); | |
| 63 // Run the signal callback. | 72 // Run the signal callback. |
| 64 SendPropertyChangedSignal(&signal); | 73 SendPropertyChangedSignal(&signal); |
| 65 | 74 |
| 66 // Reset the handler. | 75 // Remove the observer. |
| 67 client_->ResetPropertyChangedHandler(dbus::ObjectPath(kExampleServicePath)); | 76 client_->RemovePropertyChangedObserver( |
| 77 dbus::ObjectPath(kExampleServicePath), |
| 78 &observer); |
| 79 |
| 80 EXPECT_CALL(observer, OnPropertyChanged(_, _)).Times(0); |
| 81 |
| 82 // Run the signal callback again and make sure the observer isn't called. |
| 83 SendPropertyChangedSignal(&signal); |
| 68 } | 84 } |
| 69 | 85 |
| 70 TEST_F(ShillServiceClientTest, GetProperties) { | 86 TEST_F(ShillServiceClientTest, GetProperties) { |
| 71 const int kValue = 42; | 87 const int kValue = 42; |
| 72 // Create response. | 88 // Create response. |
| 73 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 89 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 74 dbus::MessageWriter writer(response.get()); | 90 dbus::MessageWriter writer(response.get()); |
| 75 dbus::MessageWriter array_writer(NULL); | 91 dbus::MessageWriter array_writer(NULL); |
| 76 writer.OpenArray("{sv}", &array_writer); | 92 writer.OpenArray("{sv}", &array_writer); |
| 77 dbus::MessageWriter entry_writer(NULL); | 93 dbus::MessageWriter entry_writer(NULL); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 101 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 117 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 102 | 118 |
| 103 // Set expectations. | 119 // Set expectations. |
| 104 const base::StringValue value(kValue); | 120 const base::StringValue value(kValue); |
| 105 PrepareForMethodCall(flimflam::kSetPropertyFunction, | 121 PrepareForMethodCall(flimflam::kSetPropertyFunction, |
| 106 base::Bind(&ExpectStringAndValueArguments, | 122 base::Bind(&ExpectStringAndValueArguments, |
| 107 flimflam::kPassphraseProperty, | 123 flimflam::kPassphraseProperty, |
| 108 &value), | 124 &value), |
| 109 response.get()); | 125 response.get()); |
| 110 // Call method. | 126 // Call method. |
| 127 MockClosure mock_closure; |
| 128 MockErrorCallback mock_error_callback; |
| 111 client_->SetProperty(dbus::ObjectPath(kExampleServicePath), | 129 client_->SetProperty(dbus::ObjectPath(kExampleServicePath), |
| 112 flimflam::kPassphraseProperty, | 130 flimflam::kPassphraseProperty, |
| 113 value, | 131 value, |
| 114 base::Bind(&ExpectNoResultValue)); | 132 mock_closure.GetCallback(), |
| 133 mock_error_callback.GetCallback()); |
| 134 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 135 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
| 136 |
| 115 // Run the message loop. | 137 // Run the message loop. |
| 116 message_loop_.RunAllPending(); | 138 message_loop_.RunAllPending(); |
| 117 } | 139 } |
| 118 | 140 |
| 119 TEST_F(ShillServiceClientTest, ClearProperty) { | 141 TEST_F(ShillServiceClientTest, ClearProperty) { |
| 120 // Create response. | 142 // Create response. |
| 121 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 143 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 122 | 144 |
| 123 // Set expectations. | 145 // Set expectations. |
| 124 PrepareForMethodCall(flimflam::kClearPropertyFunction, | 146 PrepareForMethodCall(flimflam::kClearPropertyFunction, |
| 125 base::Bind(&ExpectStringArgument, | 147 base::Bind(&ExpectStringArgument, |
| 126 flimflam::kPassphraseProperty), | 148 flimflam::kPassphraseProperty), |
| 127 response.get()); | 149 response.get()); |
| 128 // Call method. | 150 // Call method. |
| 151 MockClosure mock_closure; |
| 152 MockErrorCallback mock_error_callback; |
| 129 client_->ClearProperty(dbus::ObjectPath(kExampleServicePath), | 153 client_->ClearProperty(dbus::ObjectPath(kExampleServicePath), |
| 130 flimflam::kPassphraseProperty, | 154 flimflam::kPassphraseProperty, |
| 131 base::Bind(&ExpectNoResultValue)); | 155 mock_closure.GetCallback(), |
| 156 mock_error_callback.GetCallback()); |
| 157 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 158 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
| 159 |
| 132 // Run the message loop. | 160 // Run the message loop. |
| 133 message_loop_.RunAllPending(); | 161 message_loop_.RunAllPending(); |
| 134 } | 162 } |
| 135 | 163 |
| 136 TEST_F(ShillServiceClientTest, Connect) { | 164 TEST_F(ShillServiceClientTest, Connect) { |
| 137 // Create response. | 165 // Create response. |
| 138 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 166 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 139 | 167 |
| 140 // Set expectations. | 168 // Set expectations. |
| 141 MockClosure mock_closure; | 169 MockClosure mock_closure; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 155 | 183 |
| 156 TEST_F(ShillServiceClientTest, Disconnect) { | 184 TEST_F(ShillServiceClientTest, Disconnect) { |
| 157 // Create response. | 185 // Create response. |
| 158 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 186 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 159 | 187 |
| 160 // Set expectations. | 188 // Set expectations. |
| 161 PrepareForMethodCall(flimflam::kDisconnectFunction, | 189 PrepareForMethodCall(flimflam::kDisconnectFunction, |
| 162 base::Bind(&ExpectNoArgument), | 190 base::Bind(&ExpectNoArgument), |
| 163 response.get()); | 191 response.get()); |
| 164 // Call method. | 192 // Call method. |
| 193 MockClosure mock_closure; |
| 194 MockErrorCallback mock_error_callback; |
| 165 client_->Disconnect(dbus::ObjectPath(kExampleServicePath), | 195 client_->Disconnect(dbus::ObjectPath(kExampleServicePath), |
| 166 base::Bind(&ExpectNoResultValue)); | 196 mock_closure.GetCallback(), |
| 197 mock_error_callback.GetCallback()); |
| 198 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 199 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
| 200 |
| 167 // Run the message loop. | 201 // Run the message loop. |
| 168 message_loop_.RunAllPending(); | 202 message_loop_.RunAllPending(); |
| 169 } | 203 } |
| 170 | 204 |
| 171 TEST_F(ShillServiceClientTest, Remove) { | 205 TEST_F(ShillServiceClientTest, Remove) { |
| 172 // Create response. | 206 // Create response. |
| 173 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 207 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 174 | 208 |
| 175 // Set expectations. | 209 // Set expectations. |
| 176 PrepareForMethodCall(flimflam::kRemoveServiceFunction, | 210 PrepareForMethodCall(flimflam::kRemoveServiceFunction, |
| 177 base::Bind(&ExpectNoArgument), | 211 base::Bind(&ExpectNoArgument), |
| 178 response.get()); | 212 response.get()); |
| 179 // Call method. | 213 // Call method. |
| 214 MockClosure mock_closure; |
| 215 MockErrorCallback mock_error_callback; |
| 180 client_->Remove(dbus::ObjectPath(kExampleServicePath), | 216 client_->Remove(dbus::ObjectPath(kExampleServicePath), |
| 181 base::Bind(&ExpectNoResultValue)); | 217 mock_closure.GetCallback(), |
| 218 mock_error_callback.GetCallback()); |
| 219 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 220 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
| 221 |
| 182 // Run the message loop. | 222 // Run the message loop. |
| 183 message_loop_.RunAllPending(); | 223 message_loop_.RunAllPending(); |
| 184 } | 224 } |
| 185 | 225 |
| 186 TEST_F(ShillServiceClientTest, ActivateCellularModem) { | 226 TEST_F(ShillServiceClientTest, ActivateCellularModem) { |
| 187 const char kCarrier[] = "carrier"; | 227 const char kCarrier[] = "carrier"; |
| 188 // Create response. | 228 // Create response. |
| 189 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 229 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 190 | 230 |
| 191 // Set expectations. | 231 // Set expectations. |
| 192 PrepareForMethodCall(flimflam::kActivateCellularModemFunction, | 232 PrepareForMethodCall(flimflam::kActivateCellularModemFunction, |
| 193 base::Bind(&ExpectStringArgument, kCarrier), | 233 base::Bind(&ExpectStringArgument, kCarrier), |
| 194 response.get()); | 234 response.get()); |
| 195 // Call method. | 235 // Call method. |
| 236 MockClosure mock_closure; |
| 237 MockErrorCallback mock_error_callback; |
| 196 client_->ActivateCellularModem(dbus::ObjectPath(kExampleServicePath), | 238 client_->ActivateCellularModem(dbus::ObjectPath(kExampleServicePath), |
| 197 kCarrier, | 239 kCarrier, |
| 198 base::Bind(&ExpectNoResultValue)); | 240 mock_closure.GetCallback(), |
| 241 mock_error_callback.GetCallback()); |
| 242 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 243 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
| 244 |
| 199 // Run the message loop. | 245 // Run the message loop. |
| 200 message_loop_.RunAllPending(); | 246 message_loop_.RunAllPending(); |
| 201 } | 247 } |
| 202 | 248 |
| 203 TEST_F(ShillServiceClientTest, CallActivateCellularModemAndBlock) { | 249 TEST_F(ShillServiceClientTest, CallActivateCellularModemAndBlock) { |
| 204 const char kCarrier[] = "carrier"; | 250 const char kCarrier[] = "carrier"; |
| 205 // Create response. | 251 // Create response. |
| 206 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 252 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 207 | 253 |
| 208 // Set expectations. | 254 // Set expectations. |
| 209 PrepareForMethodCall(flimflam::kActivateCellularModemFunction, | 255 PrepareForMethodCall(flimflam::kActivateCellularModemFunction, |
| 210 base::Bind(&ExpectStringArgument, kCarrier), | 256 base::Bind(&ExpectStringArgument, kCarrier), |
| 211 response.get()); | 257 response.get()); |
| 212 // Call method. | 258 // Call method. |
| 213 const bool result = client_->CallActivateCellularModemAndBlock( | 259 const bool result = client_->CallActivateCellularModemAndBlock( |
| 214 dbus::ObjectPath(kExampleServicePath), kCarrier); | 260 dbus::ObjectPath(kExampleServicePath), kCarrier); |
| 215 EXPECT_TRUE(result); | 261 EXPECT_TRUE(result); |
| 216 } | 262 } |
| 217 | 263 |
| 218 } // namespace chromeos | 264 } // namespace chromeos |
| OLD | NEW |