| 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/flimflam_client_unittest_base.h" | 7 #include "chromeos/dbus/shill_client_unittest_base.h" |
| 8 #include "chromeos/dbus/flimflam_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 namespace chromeos { | 15 namespace chromeos { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 const char kExampleServicePath[] = "/foo/bar"; | 19 const char kExampleServicePath[] = "/foo/bar"; |
| 20 | 20 |
| 21 } // namespace | 21 } // namespace |
| 22 | 22 |
| 23 class FlimflamServiceClientTest : public FlimflamClientUnittestBase { | 23 class ShillServiceClientTest : public ShillClientUnittestBase { |
| 24 public: | 24 public: |
| 25 FlimflamServiceClientTest() | 25 ShillServiceClientTest() |
| 26 : FlimflamClientUnittestBase(flimflam::kFlimflamServiceInterface, | 26 : ShillClientUnittestBase(flimflam::kFlimflamServiceInterface, |
| 27 dbus::ObjectPath(kExampleServicePath)) { | 27 dbus::ObjectPath(kExampleServicePath)) { |
| 28 } | 28 } |
| 29 | 29 |
| 30 virtual void SetUp() { | 30 virtual void SetUp() { |
| 31 FlimflamClientUnittestBase::SetUp(); | 31 ShillClientUnittestBase::SetUp(); |
| 32 // Create a client with the mock bus. | 32 // Create a client with the mock bus. |
| 33 client_.reset(FlimflamServiceClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION, | 33 client_.reset(ShillServiceClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION, |
| 34 mock_bus_)); | 34 mock_bus_)); |
| 35 // Run the message loop to run the signal connection result callback. | 35 // Run the message loop to run the signal connection result callback. |
| 36 message_loop_.RunAllPending(); | 36 message_loop_.RunAllPending(); |
| 37 } | 37 } |
| 38 | 38 |
| 39 virtual void TearDown() { | 39 virtual void TearDown() { |
| 40 FlimflamClientUnittestBase::TearDown(); | 40 ShillClientUnittestBase::TearDown(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 protected: | 43 protected: |
| 44 scoped_ptr<FlimflamServiceClient> client_; | 44 scoped_ptr<ShillServiceClient> client_; |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 TEST_F(FlimflamServiceClientTest, PropertyChanged) { | 47 TEST_F(ShillServiceClientTest, PropertyChanged) { |
| 48 const int kValue = 42; | 48 const int kValue = 42; |
| 49 // Create a signal. | 49 // Create a signal. |
| 50 dbus::Signal signal(flimflam::kFlimflamServiceInterface, | 50 dbus::Signal signal(flimflam::kFlimflamServiceInterface, |
| 51 flimflam::kMonitorPropertyChanged); | 51 flimflam::kMonitorPropertyChanged); |
| 52 dbus::MessageWriter writer(&signal); | 52 dbus::MessageWriter writer(&signal); |
| 53 writer.AppendString(flimflam::kSignalStrengthProperty); | 53 writer.AppendString(flimflam::kSignalStrengthProperty); |
| 54 writer.AppendVariantOfByte(kValue); | 54 writer.AppendVariantOfByte(kValue); |
| 55 | 55 |
| 56 // Set expectations. | 56 // Set expectations. |
| 57 const base::FundamentalValue value(kValue); | 57 const base::FundamentalValue value(kValue); |
| 58 client_->SetPropertyChangedHandler( | 58 client_->SetPropertyChangedHandler( |
| 59 dbus::ObjectPath(kExampleServicePath), | 59 dbus::ObjectPath(kExampleServicePath), |
| 60 base::Bind(&ExpectPropertyChanged, | 60 base::Bind(&ExpectPropertyChanged, |
| 61 flimflam::kSignalStrengthProperty, | 61 flimflam::kSignalStrengthProperty, |
| 62 &value)); | 62 &value)); |
| 63 // Run the signal callback. | 63 // Run the signal callback. |
| 64 SendPropertyChangedSignal(&signal); | 64 SendPropertyChangedSignal(&signal); |
| 65 | 65 |
| 66 // Reset the handler. | 66 // Reset the handler. |
| 67 client_->ResetPropertyChangedHandler(dbus::ObjectPath(kExampleServicePath)); | 67 client_->ResetPropertyChangedHandler(dbus::ObjectPath(kExampleServicePath)); |
| 68 } | 68 } |
| 69 | 69 |
| 70 TEST_F(FlimflamServiceClientTest, GetProperties) { | 70 TEST_F(ShillServiceClientTest, GetProperties) { |
| 71 const int kValue = 42; | 71 const int kValue = 42; |
| 72 // Create response. | 72 // Create response. |
| 73 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 73 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 74 dbus::MessageWriter writer(response.get()); | 74 dbus::MessageWriter writer(response.get()); |
| 75 dbus::MessageWriter array_writer(NULL); | 75 dbus::MessageWriter array_writer(NULL); |
| 76 writer.OpenArray("{sv}", &array_writer); | 76 writer.OpenArray("{sv}", &array_writer); |
| 77 dbus::MessageWriter entry_writer(NULL); | 77 dbus::MessageWriter entry_writer(NULL); |
| 78 array_writer.OpenDictEntry(&entry_writer); | 78 array_writer.OpenDictEntry(&entry_writer); |
| 79 entry_writer.AppendString(flimflam::kSignalStrengthProperty); | 79 entry_writer.AppendString(flimflam::kSignalStrengthProperty); |
| 80 entry_writer.AppendVariantOfByte(kValue); | 80 entry_writer.AppendVariantOfByte(kValue); |
| 81 array_writer.CloseContainer(&entry_writer); | 81 array_writer.CloseContainer(&entry_writer); |
| 82 writer.CloseContainer(&array_writer); | 82 writer.CloseContainer(&array_writer); |
| 83 | 83 |
| 84 // Set expectations. | 84 // Set expectations. |
| 85 base::DictionaryValue value; | 85 base::DictionaryValue value; |
| 86 value.SetWithoutPathExpansion(flimflam::kSignalStrengthProperty, | 86 value.SetWithoutPathExpansion(flimflam::kSignalStrengthProperty, |
| 87 base::Value::CreateIntegerValue(kValue)); | 87 base::Value::CreateIntegerValue(kValue)); |
| 88 PrepareForMethodCall(flimflam::kGetPropertiesFunction, | 88 PrepareForMethodCall(flimflam::kGetPropertiesFunction, |
| 89 base::Bind(&ExpectNoArgument), | 89 base::Bind(&ExpectNoArgument), |
| 90 response.get()); | 90 response.get()); |
| 91 // Call method. | 91 // Call method. |
| 92 client_->GetProperties(dbus::ObjectPath(kExampleServicePath), | 92 client_->GetProperties(dbus::ObjectPath(kExampleServicePath), |
| 93 base::Bind(&ExpectDictionaryValueResult, &value)); | 93 base::Bind(&ExpectDictionaryValueResult, &value)); |
| 94 // Run the message loop. | 94 // Run the message loop. |
| 95 message_loop_.RunAllPending(); | 95 message_loop_.RunAllPending(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 TEST_F(FlimflamServiceClientTest, SetProperty) { | 98 TEST_F(ShillServiceClientTest, SetProperty) { |
| 99 const char kValue[] = "passphrase"; | 99 const char kValue[] = "passphrase"; |
| 100 // Create response. | 100 // Create response. |
| 101 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 101 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 102 | 102 |
| 103 // Set expectations. | 103 // Set expectations. |
| 104 const base::StringValue value(kValue); | 104 const base::StringValue value(kValue); |
| 105 PrepareForMethodCall(flimflam::kSetPropertyFunction, | 105 PrepareForMethodCall(flimflam::kSetPropertyFunction, |
| 106 base::Bind(&ExpectStringAndValueArguments, | 106 base::Bind(&ExpectStringAndValueArguments, |
| 107 flimflam::kPassphraseProperty, | 107 flimflam::kPassphraseProperty, |
| 108 &value), | 108 &value), |
| 109 response.get()); | 109 response.get()); |
| 110 // Call method. | 110 // Call method. |
| 111 client_->SetProperty(dbus::ObjectPath(kExampleServicePath), | 111 client_->SetProperty(dbus::ObjectPath(kExampleServicePath), |
| 112 flimflam::kPassphraseProperty, | 112 flimflam::kPassphraseProperty, |
| 113 value, | 113 value, |
| 114 base::Bind(&ExpectNoResultValue)); | 114 base::Bind(&ExpectNoResultValue)); |
| 115 // Run the message loop. | 115 // Run the message loop. |
| 116 message_loop_.RunAllPending(); | 116 message_loop_.RunAllPending(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 TEST_F(FlimflamServiceClientTest, ClearProperty) { | 119 TEST_F(ShillServiceClientTest, ClearProperty) { |
| 120 // Create response. | 120 // Create response. |
| 121 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 121 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 122 | 122 |
| 123 // Set expectations. | 123 // Set expectations. |
| 124 PrepareForMethodCall(flimflam::kClearPropertyFunction, | 124 PrepareForMethodCall(flimflam::kClearPropertyFunction, |
| 125 base::Bind(&ExpectStringArgument, | 125 base::Bind(&ExpectStringArgument, |
| 126 flimflam::kPassphraseProperty), | 126 flimflam::kPassphraseProperty), |
| 127 response.get()); | 127 response.get()); |
| 128 // Call method. | 128 // Call method. |
| 129 client_->ClearProperty(dbus::ObjectPath(kExampleServicePath), | 129 client_->ClearProperty(dbus::ObjectPath(kExampleServicePath), |
| 130 flimflam::kPassphraseProperty, | 130 flimflam::kPassphraseProperty, |
| 131 base::Bind(&ExpectNoResultValue)); | 131 base::Bind(&ExpectNoResultValue)); |
| 132 // Run the message loop. | 132 // Run the message loop. |
| 133 message_loop_.RunAllPending(); | 133 message_loop_.RunAllPending(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 TEST_F(FlimflamServiceClientTest, Connect) { | 136 TEST_F(ShillServiceClientTest, Connect) { |
| 137 // Create response. | 137 // Create response. |
| 138 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 138 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 139 | 139 |
| 140 // Set expectations. | 140 // Set expectations. |
| 141 MockClosure mock_closure; | 141 MockClosure mock_closure; |
| 142 MockErrorCallback mock_error_callback; | 142 MockErrorCallback mock_error_callback; |
| 143 PrepareForMethodCall(flimflam::kConnectFunction, | 143 PrepareForMethodCall(flimflam::kConnectFunction, |
| 144 base::Bind(&ExpectNoArgument), | 144 base::Bind(&ExpectNoArgument), |
| 145 response.get()); | 145 response.get()); |
| 146 EXPECT_CALL(mock_closure, Run()).Times(1); | 146 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 147 // Call method. | 147 // Call method. |
| 148 client_->Connect(dbus::ObjectPath(kExampleServicePath), | 148 client_->Connect(dbus::ObjectPath(kExampleServicePath), |
| 149 mock_closure.GetCallback(), | 149 mock_closure.GetCallback(), |
| 150 mock_error_callback.GetCallback()); | 150 mock_error_callback.GetCallback()); |
| 151 | 151 |
| 152 // Run the message loop. | 152 // Run the message loop. |
| 153 message_loop_.RunAllPending(); | 153 message_loop_.RunAllPending(); |
| 154 } | 154 } |
| 155 | 155 |
| 156 TEST_F(FlimflamServiceClientTest, Disconnect) { | 156 TEST_F(ShillServiceClientTest, Disconnect) { |
| 157 // Create response. | 157 // Create response. |
| 158 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 158 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 159 | 159 |
| 160 // Set expectations. | 160 // Set expectations. |
| 161 PrepareForMethodCall(flimflam::kDisconnectFunction, | 161 PrepareForMethodCall(flimflam::kDisconnectFunction, |
| 162 base::Bind(&ExpectNoArgument), | 162 base::Bind(&ExpectNoArgument), |
| 163 response.get()); | 163 response.get()); |
| 164 // Call method. | 164 // Call method. |
| 165 client_->Disconnect(dbus::ObjectPath(kExampleServicePath), | 165 client_->Disconnect(dbus::ObjectPath(kExampleServicePath), |
| 166 base::Bind(&ExpectNoResultValue)); | 166 base::Bind(&ExpectNoResultValue)); |
| 167 // Run the message loop. | 167 // Run the message loop. |
| 168 message_loop_.RunAllPending(); | 168 message_loop_.RunAllPending(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 TEST_F(FlimflamServiceClientTest, Remove) { | 171 TEST_F(ShillServiceClientTest, Remove) { |
| 172 // Create response. | 172 // Create response. |
| 173 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 173 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 174 | 174 |
| 175 // Set expectations. | 175 // Set expectations. |
| 176 PrepareForMethodCall(flimflam::kRemoveServiceFunction, | 176 PrepareForMethodCall(flimflam::kRemoveServiceFunction, |
| 177 base::Bind(&ExpectNoArgument), | 177 base::Bind(&ExpectNoArgument), |
| 178 response.get()); | 178 response.get()); |
| 179 // Call method. | 179 // Call method. |
| 180 client_->Remove(dbus::ObjectPath(kExampleServicePath), | 180 client_->Remove(dbus::ObjectPath(kExampleServicePath), |
| 181 base::Bind(&ExpectNoResultValue)); | 181 base::Bind(&ExpectNoResultValue)); |
| 182 // Run the message loop. | 182 // Run the message loop. |
| 183 message_loop_.RunAllPending(); | 183 message_loop_.RunAllPending(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 TEST_F(FlimflamServiceClientTest, ActivateCellularModem) { | 186 TEST_F(ShillServiceClientTest, ActivateCellularModem) { |
| 187 const char kCarrier[] = "carrier"; | 187 const char kCarrier[] = "carrier"; |
| 188 // Create response. | 188 // Create response. |
| 189 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 189 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 190 | 190 |
| 191 // Set expectations. | 191 // Set expectations. |
| 192 PrepareForMethodCall(flimflam::kActivateCellularModemFunction, | 192 PrepareForMethodCall(flimflam::kActivateCellularModemFunction, |
| 193 base::Bind(&ExpectStringArgument, kCarrier), | 193 base::Bind(&ExpectStringArgument, kCarrier), |
| 194 response.get()); | 194 response.get()); |
| 195 // Call method. | 195 // Call method. |
| 196 client_->ActivateCellularModem(dbus::ObjectPath(kExampleServicePath), | 196 client_->ActivateCellularModem(dbus::ObjectPath(kExampleServicePath), |
| 197 kCarrier, | 197 kCarrier, |
| 198 base::Bind(&ExpectNoResultValue)); | 198 base::Bind(&ExpectNoResultValue)); |
| 199 // Run the message loop. | 199 // Run the message loop. |
| 200 message_loop_.RunAllPending(); | 200 message_loop_.RunAllPending(); |
| 201 } | 201 } |
| 202 | 202 |
| 203 TEST_F(FlimflamServiceClientTest, CallActivateCellularModemAndBlock) { | 203 TEST_F(ShillServiceClientTest, CallActivateCellularModemAndBlock) { |
| 204 const char kCarrier[] = "carrier"; | 204 const char kCarrier[] = "carrier"; |
| 205 // Create response. | 205 // Create response. |
| 206 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 206 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 207 | 207 |
| 208 // Set expectations. | 208 // Set expectations. |
| 209 PrepareForMethodCall(flimflam::kActivateCellularModemFunction, | 209 PrepareForMethodCall(flimflam::kActivateCellularModemFunction, |
| 210 base::Bind(&ExpectStringArgument, kCarrier), | 210 base::Bind(&ExpectStringArgument, kCarrier), |
| 211 response.get()); | 211 response.get()); |
| 212 // Call method. | 212 // Call method. |
| 213 const bool result = client_->CallActivateCellularModemAndBlock( | 213 const bool result = client_->CallActivateCellularModemAndBlock( |
| 214 dbus::ObjectPath(kExampleServicePath), kCarrier); | 214 dbus::ObjectPath(kExampleServicePath), kCarrier); |
| 215 EXPECT_TRUE(result); | 215 EXPECT_TRUE(result); |
| 216 } | 216 } |
| 217 | 217 |
| 218 } // namespace chromeos | 218 } // namespace chromeos |
| OLD | NEW |