diff options
author | gspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-07 15:12:32 +0000 |
---|---|---|
committer | gspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-07 15:12:32 +0000 |
commit | dc98bb2643a9df4a6ca0f4a2b10ca3f30e071a6f (patch) | |
tree | 3b1f29e46ae4b7151ef9f0c9f492f001c5a1a2a4 /chromeos | |
parent | 8f64625aa018c789968f2ae65ccf707abb341125 (diff) | |
download | chromium_src-dc98bb2643a9df4a6ca0f4a2b10ca3f30e071a6f.zip chromium_src-dc98bb2643a9df4a6ca0f4a2b10ca3f30e071a6f.tar.gz chromium_src-dc98bb2643a9df4a6ca0f4a2b10ca3f30e071a6f.tar.bz2 |
Added ClearProperties to the Shill service client.
Must be committed only after the corresponding service_constants.h
change goes in.
BUG=chromium-os:35900
TEST=built
Review URL: https://chromiumcodereview.appspot.com/11364089
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166427 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r-- | chromeos/dbus/dbus_method_call_status.h | 2 | ||||
-rw-r--r-- | chromeos/dbus/mock_shill_service_client.h | 4 | ||||
-rw-r--r-- | chromeos/dbus/shill_client_helper.cc | 30 | ||||
-rw-r--r-- | chromeos/dbus/shill_client_helper.h | 21 | ||||
-rw-r--r-- | chromeos/dbus/shill_client_unittest_base.cc | 21 | ||||
-rw-r--r-- | chromeos/dbus/shill_client_unittest_base.h | 14 | ||||
-rw-r--r-- | chromeos/dbus/shill_service_client.cc | 54 | ||||
-rw-r--r-- | chromeos/dbus/shill_service_client.h | 12 | ||||
-rw-r--r-- | chromeos/dbus/shill_service_client_unittest.cc | 47 |
9 files changed, 191 insertions, 14 deletions
diff --git a/chromeos/dbus/dbus_method_call_status.h b/chromeos/dbus/dbus_method_call_status.h index 29fa84f..89cae4a 100644 --- a/chromeos/dbus/dbus_method_call_status.h +++ b/chromeos/dbus/dbus_method_call_status.h @@ -40,7 +40,7 @@ typedef base::Callback<void( const dbus::ObjectPath& result)> ObjectPathDBusMethodCallback; // A callback to handle responses of methods returning a ObjectPath value that -// doens't get call status. +// doesn't get call status. typedef base::Callback<void(const dbus::ObjectPath& result)> ObjectPathCallback; } // namespace chromeos diff --git a/chromeos/dbus/mock_shill_service_client.h b/chromeos/dbus/mock_shill_service_client.h index 434d9ca..96e2e57 100644 --- a/chromeos/dbus/mock_shill_service_client.h +++ b/chromeos/dbus/mock_shill_service_client.h @@ -35,6 +35,10 @@ class MockShillServiceClient : public ShillServiceClient { const std::string& name, const base::Closure& callback, const ErrorCallback& error_callback)); + MOCK_METHOD4(ClearProperties, void(const dbus::ObjectPath& service_path, + const std::vector<std::string>& names, + const ListValueCallback& callback, + const ErrorCallback& error_callback)); MOCK_METHOD3(Connect, void(const dbus::ObjectPath& service_path, const base::Closure& callback, const ErrorCallback& error_callback)); diff --git a/chromeos/dbus/shill_client_helper.cc b/chromeos/dbus/shill_client_helper.cc index f6d0fdc..497e0fd 100644 --- a/chromeos/dbus/shill_client_helper.cc +++ b/chromeos/dbus/shill_client_helper.cc @@ -125,6 +125,22 @@ void ShillClientHelper::CallDictionaryValueMethodWithErrorCallback( error_callback)); } +void ShillClientHelper::CallListValueMethodWithErrorCallback( + dbus::MethodCall* method_call, + const ListValueCallback& callback, + const ErrorCallback& error_callback) { + proxy_->CallMethodWithErrorCallback( + method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, + base::Bind( + &ShillClientHelper::OnListValueMethodWithErrorCallback, + weak_ptr_factory_.GetWeakPtr(), + callback, + error_callback), + base::Bind(&ShillClientHelper::OnError, + weak_ptr_factory_.GetWeakPtr(), + error_callback)); +} + bool ShillClientHelper::CallVoidMethodAndBlock( dbus::MethodCall* method_call) { scoped_ptr<dbus::Response> response( @@ -312,6 +328,20 @@ void ShillClientHelper::OnDictionaryValueMethodWithErrorCallback( callback.Run(*result); } +void ShillClientHelper::OnListValueMethodWithErrorCallback( + const ListValueCallback& callback, + const ErrorCallback& error_callback, + dbus::Response* response) { + dbus::MessageReader reader(response); + scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); + base::ListValue* result = NULL; + if (!value.get() || !value->GetAsList(&result)) { + error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); + return; + } + callback.Run(*result); +} + void ShillClientHelper::OnError(const ErrorCallback& error_callback, dbus::ErrorResponse* response) { std::string error_name; diff --git a/chromeos/dbus/shill_client_helper.h b/chromeos/dbus/shill_client_helper.h index 8782d90..1ad3b86 100644 --- a/chromeos/dbus/shill_client_helper.h +++ b/chromeos/dbus/shill_client_helper.h @@ -11,6 +11,7 @@ #include "base/callback.h" #include "base/memory/weak_ptr.h" #include "base/observer_list.h" +#include "base/values.h" #include "chromeos/dbus/blocking_method_caller.h" #include "chromeos/dbus/dbus_method_call_status.h" #include "chromeos/dbus/shill_property_changed_observer.h" @@ -51,8 +52,11 @@ class ShillClientHelper { // A callback to handle responses for methods with DictionaryValue results. // This is used by CallDictionaryValueMethodWithErrorCallback. - typedef base::Callback<void(const base::DictionaryValue& result - )> DictionaryValueCallbackWithoutStatus; + typedef base::Callback<void(const base::DictionaryValue& result)> + DictionaryValueCallbackWithoutStatus; + + // A callback to handle responses of methods returning a ListValue. + typedef base::Callback<void(const base::ListValue& result)> ListValueCallback; // A callback to handle errors for method call. typedef base::Callback<void(const std::string& error_name, @@ -100,6 +104,12 @@ class ShillClientHelper { const DictionaryValueCallbackWithoutStatus& callback, const ErrorCallback& error_callback); + // Calls a method with a boolean array result with error callback. + void CallListValueMethodWithErrorCallback( + dbus::MethodCall* method_call, + const ListValueCallback& callback, + const ErrorCallback& error_callback); + // DEPRECATED DO NOT USE: Calls a method without results. bool CallVoidMethodAndBlock(dbus::MethodCall* method_call); @@ -156,6 +166,13 @@ class ShillClientHelper { const ErrorCallback& error_callback, dbus::Response* response); + // Handles responses for methods with Boolean array results. + // Used by CallBooleanArrayMethodWithErrorCallback(). + void OnListValueMethodWithErrorCallback( + const ListValueCallback& callback, + const ErrorCallback& error_callback, + dbus::Response* response); + // Handles errors for method calls. void OnError(const ErrorCallback& error_callback, dbus::ErrorResponse* response); diff --git a/chromeos/dbus/shill_client_unittest_base.cc b/chromeos/dbus/shill_client_unittest_base.cc index 1907cb0..7488fa9 100644 --- a/chromeos/dbus/shill_client_unittest_base.cc +++ b/chromeos/dbus/shill_client_unittest_base.cc @@ -54,6 +54,7 @@ void ValueMatcher::DescribeNegationTo(::std::ostream* os) const { *os << "value does not equal " << expected_value_str; } + ShillClientUnittestBase::MockClosure::MockClosure() {} ShillClientUnittestBase::MockClosure::~MockClosure() {} @@ -63,6 +64,16 @@ base::Closure ShillClientUnittestBase::MockClosure::GetCallback() { } +ShillClientUnittestBase::MockListValueCallback::MockListValueCallback() {} + +ShillClientUnittestBase::MockListValueCallback::~MockListValueCallback() {} + +ShillClientHelper::ListValueCallback +ShillClientUnittestBase::MockListValueCallback::GetCallback() { + return base::Bind(&MockListValueCallback::Run, base::Unretained(this)); +} + + ShillClientUnittestBase::MockErrorCallback::MockErrorCallback() {} ShillClientUnittestBase::MockErrorCallback::~MockErrorCallback() {} @@ -187,6 +198,16 @@ void ShillClientUnittestBase::ExpectStringArgument( } // static +void ShillClientUnittestBase::ExpectArrayOfStringsArgument( + const std::vector<std::string>& expected_strings, + dbus::MessageReader* reader) { + std::vector<std::string> strs; + ASSERT_TRUE(reader->PopArrayOfStrings(&strs)); + EXPECT_EQ(expected_strings, strs); + EXPECT_FALSE(reader->HasMoreData()); +} + +// static void ShillClientUnittestBase::ExpectValueArgument( const base::Value* expected_value, dbus::MessageReader* reader) { diff --git a/chromeos/dbus/shill_client_unittest_base.h b/chromeos/dbus/shill_client_unittest_base.h index 96f4e93..f893bfd 100644 --- a/chromeos/dbus/shill_client_unittest_base.h +++ b/chromeos/dbus/shill_client_unittest_base.h @@ -69,13 +69,21 @@ class ShillClientUnittestBase : public testing::Test { base::Closure GetCallback(); }; + class MockListValueCallback { + public: + MockListValueCallback(); + ~MockListValueCallback(); + MOCK_METHOD1(Run, void(const base::ListValue& list)); + ShillClientHelper::ListValueCallback GetCallback(); + }; + // A mock ErrorCallback. class MockErrorCallback { public: MockErrorCallback(); ~MockErrorCallback(); MOCK_METHOD2(Run, void(const std::string& error_name, - const std::string& error_mesage)); + const std::string& error_message)); ShillClientHelper::ErrorCallback GetCallback(); }; @@ -122,6 +130,10 @@ class ShillClientUnittestBase : public testing::Test { static void ExpectStringArgument(const std::string& expected_string, dbus::MessageReader* reader); + static void ExpectArrayOfStringsArgument( + const std::vector<std::string>& expected_strings, + dbus::MessageReader* reader); + // Expects the reader to have a Value. static void ExpectValueArgument(const base::Value* expected_value, dbus::MessageReader* reader); diff --git a/chromeos/dbus/shill_service_client.cc b/chromeos/dbus/shill_service_client.cc index 9899f2a..f0e601d 100644 --- a/chromeos/dbus/shill_service_client.cc +++ b/chromeos/dbus/shill_service_client.cc @@ -100,6 +100,21 @@ class ShillServiceClientImpl : public ShillServiceClient { error_callback); } + + virtual void ClearProperties(const dbus::ObjectPath& service_path, + const std::vector<std::string>& names, + const ListValueCallback& callback, + const ErrorCallback& error_callback) OVERRIDE { + dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, + shill::kClearPropertiesFunction); + dbus::MessageWriter writer(&method_call); + writer.AppendArrayOfStrings(names); + GetHelper(service_path)->CallListValueMethodWithErrorCallback( + &method_call, + callback, + error_callback); + } + virtual void Connect(const dbus::ObjectPath& service_path, const base::Closure& callback, const ErrorCallback& error_callback) OVERRIDE { @@ -250,6 +265,40 @@ class ShillServiceClientStubImpl : public ShillServiceClient, } dict->Remove(name, NULL); MessageLoop::current()->PostTask(FROM_HERE, callback); + MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind(&ShillServiceClientStubImpl::NotifyObserversPropertyChanged, + weak_ptr_factory_.GetWeakPtr(), service_path, name)); + } + + virtual void ClearProperties(const dbus::ObjectPath& service_path, + const std::vector<std::string>& names, + const ListValueCallback& callback, + const ErrorCallback& error_callback) OVERRIDE { + base::DictionaryValue* dict = NULL; + if (!stub_services_.GetDictionaryWithoutPathExpansion( + service_path.value(), &dict)) { + error_callback.Run("StubError", "Service not found"); + return; + } + scoped_ptr<base::ListValue> results(new base::ListValue); + for (std::vector<std::string>::const_iterator iter = names.begin(); + iter != names.end(); ++iter) { + dict->Remove(*iter, NULL); + results->AppendBoolean(true); + } + MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind(&ShillServiceClientStubImpl::PassStubListValue, + callback, base::Owned(results.release()))); + for (std::vector<std::string>::const_iterator iter = names.begin(); + iter != names.end(); ++iter) { + MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind( + &ShillServiceClientStubImpl::NotifyObserversPropertyChanged, + weak_ptr_factory_.GetWeakPtr(), service_path, *iter)); + } } virtual void Connect(const dbus::ObjectPath& service_path, @@ -367,6 +416,11 @@ class ShillServiceClientStubImpl : public ShillServiceClient, callback.Run(DBUS_METHOD_CALL_SUCCESS, *dict); } + static void PassStubListValue(const ListValueCallback& callback, + base::ListValue* value) { + callback.Run(*value); + } + void NotifyObserversPropertyChanged(const dbus::ObjectPath& service_path, const std::string& property) { base::DictionaryValue* dict = NULL; diff --git a/chromeos/dbus/shill_service_client.h b/chromeos/dbus/shill_service_client.h index 44fb9ba..07c1cba 100644 --- a/chromeos/dbus/shill_service_client.h +++ b/chromeos/dbus/shill_service_client.h @@ -37,10 +37,11 @@ class CHROMEOS_EXPORT ShillServiceClient { public: typedef ShillClientHelper::PropertyChangedHandler PropertyChangedHandler; typedef ShillClientHelper::DictionaryValueCallback DictionaryValueCallback; + typedef ShillClientHelper::ListValueCallback ListValueCallback; typedef ShillClientHelper::ErrorCallback ErrorCallback; - // Interface for setting up services for testing. - // Accessed through GetTestInterface(), only implemented in the Stub Impl. + // Interface for setting up services for testing. Accessed through + // GetTestInterface(), only implemented in the stub implementation. class TestInterface { public: virtual void AddService(const std::string& service_path, @@ -93,6 +94,13 @@ class CHROMEOS_EXPORT ShillServiceClient { const base::Closure& callback, const ErrorCallback& error_callback) = 0; + // Calls ClearProperties method. + // |callback| is called after the method call succeeds. + virtual void ClearProperties(const dbus::ObjectPath& service_path, + const std::vector<std::string>& names, + const ListValueCallback& callback, + const ErrorCallback& error_callback) = 0; + // Calls Connect method. // |callback| is called after the method call succeeds. virtual void Connect(const dbus::ObjectPath& service_path, diff --git a/chromeos/dbus/shill_service_client_unittest.cc b/chromeos/dbus/shill_service_client_unittest.cc index 93a9731..736c215 100644 --- a/chromeos/dbus/shill_service_client_unittest.cc +++ b/chromeos/dbus/shill_service_client_unittest.cc @@ -36,7 +36,7 @@ class ShillServiceClientTest : public ShillClientUnittestBase { client_.reset(ShillServiceClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION, mock_bus_)); // Run the message loop to run the signal connection result callback. - message_loop_.RunAllPending(); + message_loop_.RunUntilIdle(); } virtual void TearDown() { @@ -108,7 +108,7 @@ TEST_F(ShillServiceClientTest, GetProperties) { client_->GetProperties(dbus::ObjectPath(kExampleServicePath), base::Bind(&ExpectDictionaryValueResult, &value)); // Run the message loop. - message_loop_.RunAllPending(); + message_loop_.RunUntilIdle(); } TEST_F(ShillServiceClientTest, SetProperty) { @@ -135,7 +135,7 @@ TEST_F(ShillServiceClientTest, SetProperty) { EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); // Run the message loop. - message_loop_.RunAllPending(); + message_loop_.RunUntilIdle(); } TEST_F(ShillServiceClientTest, ClearProperty) { @@ -158,7 +158,38 @@ TEST_F(ShillServiceClientTest, ClearProperty) { EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); // Run the message loop. - message_loop_.RunAllPending(); + message_loop_.RunUntilIdle(); +} + +TEST_F(ShillServiceClientTest, ClearProperties) { + // Create response. + scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + dbus::MessageWriter writer(response.get()); + dbus::MessageWriter array_writer(NULL); + writer.OpenArray("b", &array_writer); + array_writer.AppendBool(true); + array_writer.AppendBool(true); + writer.CloseContainer(&array_writer); + + // Set expectations. + std::vector<std::string> keys; + keys.push_back(flimflam::kPassphraseProperty); + keys.push_back(flimflam::kSignalStrengthProperty); + PrepareForMethodCall(shill::kClearPropertiesFunction, + base::Bind(&ExpectArrayOfStringsArgument, keys), + response.get()); + // Call method. + MockListValueCallback mock_list_value_callback; + MockErrorCallback mock_error_callback; + client_->ClearProperties(dbus::ObjectPath(kExampleServicePath), + keys, + mock_list_value_callback.GetCallback(), + mock_error_callback.GetCallback()); + EXPECT_CALL(mock_list_value_callback, Run(_)).Times(1); + EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); + + // Run the message loop. + message_loop_.RunUntilIdle(); } TEST_F(ShillServiceClientTest, Connect) { @@ -178,7 +209,7 @@ TEST_F(ShillServiceClientTest, Connect) { mock_error_callback.GetCallback()); // Run the message loop. - message_loop_.RunAllPending(); + message_loop_.RunUntilIdle(); } TEST_F(ShillServiceClientTest, Disconnect) { @@ -199,7 +230,7 @@ TEST_F(ShillServiceClientTest, Disconnect) { EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); // Run the message loop. - message_loop_.RunAllPending(); + message_loop_.RunUntilIdle(); } TEST_F(ShillServiceClientTest, Remove) { @@ -220,7 +251,7 @@ TEST_F(ShillServiceClientTest, Remove) { EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); // Run the message loop. - message_loop_.RunAllPending(); + message_loop_.RunUntilIdle(); } TEST_F(ShillServiceClientTest, ActivateCellularModem) { @@ -243,7 +274,7 @@ TEST_F(ShillServiceClientTest, ActivateCellularModem) { EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); // Run the message loop. - message_loop_.RunAllPending(); + message_loop_.RunUntilIdle(); } TEST_F(ShillServiceClientTest, CallActivateCellularModemAndBlock) { |