| 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_network_client.h" | 8 #include "chromeos/dbus/shill_network_client.h" |
| 9 #include "dbus/message.h" | 9 #include "dbus/message.h" |
| 10 #include "dbus/values_util.h" | 10 #include "dbus/values_util.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "third_party/cros_system_api/dbus/service_constants.h" | 12 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 13 | 13 |
| 14 namespace chromeos { | 14 namespace chromeos { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const char kExampleNetworkPath[] = "/foo/bar"; | 18 const char kExampleNetworkPath[] = "/foo/bar"; |
| 19 | 19 |
| 20 } // namespace | 20 } // namespace |
| 21 | 21 |
| 22 class FlimflamNetworkClientTest : public FlimflamClientUnittestBase { | 22 class ShillNetworkClientTest : public ShillClientUnittestBase { |
| 23 public: | 23 public: |
| 24 FlimflamNetworkClientTest() | 24 ShillNetworkClientTest() |
| 25 : FlimflamClientUnittestBase( | 25 : ShillClientUnittestBase( |
| 26 flimflam::kFlimflamNetworkInterface, | 26 flimflam::kFlimflamNetworkInterface, |
| 27 dbus::ObjectPath(kExampleNetworkPath)) { | 27 dbus::ObjectPath(kExampleNetworkPath)) { |
| 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(FlimflamNetworkClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION, | 33 client_.reset(ShillNetworkClient::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<FlimflamNetworkClient> client_; | 44 scoped_ptr<ShillNetworkClient> client_; |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 TEST_F(FlimflamNetworkClientTest, PropertyChanged) { | 47 TEST_F(ShillNetworkClientTest, PropertyChanged) { |
| 48 // Create a signal. | 48 // Create a signal. |
| 49 const base::FundamentalValue kConnected(true); | 49 const base::FundamentalValue kConnected(true); |
| 50 dbus::Signal signal(flimflam::kFlimflamNetworkInterface, | 50 dbus::Signal signal(flimflam::kFlimflamNetworkInterface, |
| 51 flimflam::kMonitorPropertyChanged); | 51 flimflam::kMonitorPropertyChanged); |
| 52 dbus::MessageWriter writer(&signal); | 52 dbus::MessageWriter writer(&signal); |
| 53 writer.AppendString(flimflam::kConnectedProperty); | 53 writer.AppendString(flimflam::kConnectedProperty); |
| 54 dbus::AppendBasicTypeValueDataAsVariant(&writer, kConnected); | 54 dbus::AppendBasicTypeValueDataAsVariant(&writer, kConnected); |
| 55 | 55 |
| 56 // Set expectations. | 56 // Set expectations. |
| 57 client_->SetPropertyChangedHandler(dbus::ObjectPath(kExampleNetworkPath), | 57 client_->SetPropertyChangedHandler(dbus::ObjectPath(kExampleNetworkPath), |
| 58 base::Bind(&ExpectPropertyChanged, | 58 base::Bind(&ExpectPropertyChanged, |
| 59 flimflam::kConnectedProperty, | 59 flimflam::kConnectedProperty, |
| 60 &kConnected)); | 60 &kConnected)); |
| 61 // Run the signal callback. | 61 // Run the signal callback. |
| 62 SendPropertyChangedSignal(&signal); | 62 SendPropertyChangedSignal(&signal); |
| 63 | 63 |
| 64 // Reset the handler. | 64 // Reset the handler. |
| 65 client_->ResetPropertyChangedHandler(dbus::ObjectPath(kExampleNetworkPath)); | 65 client_->ResetPropertyChangedHandler(dbus::ObjectPath(kExampleNetworkPath)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 TEST_F(FlimflamNetworkClientTest, GetProperties) { | 68 TEST_F(ShillNetworkClientTest, GetProperties) { |
| 69 const char kAddress[] = "address"; | 69 const char kAddress[] = "address"; |
| 70 const char kName[] = "name"; | 70 const char kName[] = "name"; |
| 71 const uint8 kSignalStrength = 1; | 71 const uint8 kSignalStrength = 1; |
| 72 const uint32 kWifiChannel = 1; | 72 const uint32 kWifiChannel = 1; |
| 73 const bool kConnected = true; | 73 const bool kConnected = true; |
| 74 | 74 |
| 75 // Create response. | 75 // Create response. |
| 76 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 76 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 77 dbus::MessageWriter writer(response.get()); | 77 dbus::MessageWriter writer(response.get()); |
| 78 dbus::MessageWriter array_writer(NULL); | 78 dbus::MessageWriter array_writer(NULL); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 PrepareForMethodCall(flimflam::kGetPropertiesFunction, | 124 PrepareForMethodCall(flimflam::kGetPropertiesFunction, |
| 125 base::Bind(&ExpectNoArgument), | 125 base::Bind(&ExpectNoArgument), |
| 126 response.get()); | 126 response.get()); |
| 127 // Call method. | 127 // Call method. |
| 128 client_->GetProperties(dbus::ObjectPath(kExampleNetworkPath), | 128 client_->GetProperties(dbus::ObjectPath(kExampleNetworkPath), |
| 129 base::Bind(&ExpectDictionaryValueResult, &value)); | 129 base::Bind(&ExpectDictionaryValueResult, &value)); |
| 130 // Run the message loop. | 130 // Run the message loop. |
| 131 message_loop_.RunAllPending(); | 131 message_loop_.RunAllPending(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 TEST_F(FlimflamNetworkClientTest, CallGetPropertiesAndBlock) { | 134 TEST_F(ShillNetworkClientTest, CallGetPropertiesAndBlock) { |
| 135 const char kName[] = "name"; | 135 const char kName[] = "name"; |
| 136 | 136 |
| 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 dbus::MessageWriter writer(response.get()); | 139 dbus::MessageWriter writer(response.get()); |
| 140 dbus::MessageWriter array_writer(NULL); | 140 dbus::MessageWriter array_writer(NULL); |
| 141 writer.OpenArray("{sv}", &array_writer); | 141 writer.OpenArray("{sv}", &array_writer); |
| 142 dbus::MessageWriter entry_writer(NULL); | 142 dbus::MessageWriter entry_writer(NULL); |
| 143 array_writer.OpenDictEntry(&entry_writer); | 143 array_writer.OpenDictEntry(&entry_writer); |
| 144 entry_writer.AppendString(flimflam::kNameProperty); | 144 entry_writer.AppendString(flimflam::kNameProperty); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 158 // Call method. | 158 // Call method. |
| 159 scoped_ptr<base::DictionaryValue> result( | 159 scoped_ptr<base::DictionaryValue> result( |
| 160 client_->CallGetPropertiesAndBlock( | 160 client_->CallGetPropertiesAndBlock( |
| 161 dbus::ObjectPath(kExampleNetworkPath))); | 161 dbus::ObjectPath(kExampleNetworkPath))); |
| 162 | 162 |
| 163 ASSERT_TRUE(result.get()); | 163 ASSERT_TRUE(result.get()); |
| 164 EXPECT_TRUE(result->Equals(&value)); | 164 EXPECT_TRUE(result->Equals(&value)); |
| 165 } | 165 } |
| 166 | 166 |
| 167 } // namespace chromeos | 167 } // namespace chromeos |
| OLD | NEW |