summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authorhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-20 06:04:32 +0000
committerhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-20 06:04:32 +0000
commit903308a94c0fdbb785aa345caa17fc7c788a4aca (patch)
tree1379325dd35ab12aaa1ae2b18fb71c653c079300 /chromeos
parentcfdf6ea30b7f72d892676e70490fb8fdb250fb28 (diff)
downloadchromium_src-903308a94c0fdbb785aa345caa17fc7c788a4aca.zip
chromium_src-903308a94c0fdbb785aa345caa17fc7c788a4aca.tar.gz
chromium_src-903308a94c0fdbb785aa345caa17fc7c788a4aca.tar.bz2
Add chromeos::FlimflamDeviceClient::CallGetPropertiesAndBlock/CallAddIPConfigAndBlock
BUG=chromium-os:16557 TEST=chromeos_unittests --gtest_filter="FlimflamDeviceClientTest.*" Review URL: http://codereview.chromium.org/10078007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133150 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/dbus/flimflam_client_helper.cc15
-rw-r--r--chromeos/dbus/flimflam_client_helper.h3
-rw-r--r--chromeos/dbus/flimflam_device_client.cc33
-rw-r--r--chromeos/dbus/flimflam_device_client.h17
-rw-r--r--chromeos/dbus/flimflam_device_client_unittest.cc64
-rw-r--r--chromeos/dbus/mock_flimflam_device_client.h5
6 files changed, 137 insertions, 0 deletions
diff --git a/chromeos/dbus/flimflam_client_helper.cc b/chromeos/dbus/flimflam_client_helper.cc
index f5ffb2f..97c91dd 100644
--- a/chromeos/dbus/flimflam_client_helper.cc
+++ b/chromeos/dbus/flimflam_client_helper.cc
@@ -79,6 +79,21 @@ bool FlimflamClientHelper::CallVoidMethodAndBlock(
return true;
}
+dbus::ObjectPath FlimflamClientHelper::CallObjectPathMethodAndBlock(
+ dbus::MethodCall* method_call) {
+ scoped_ptr<dbus::Response> response(
+ blocking_method_caller_.CallMethodAndBlock(method_call));
+ if (!response.get())
+ return dbus::ObjectPath();
+
+ dbus::MessageReader reader(response.get());
+ dbus::ObjectPath result;
+ if (!reader.PopObjectPath(&result))
+ return dbus::ObjectPath();
+
+ return result;
+}
+
base::DictionaryValue* FlimflamClientHelper::CallDictionaryValueMethodAndBlock(
dbus::MethodCall* method_call) {
scoped_ptr<dbus::Response> response(
diff --git a/chromeos/dbus/flimflam_client_helper.h b/chromeos/dbus/flimflam_client_helper.h
index 16519f2..dd2a261 100644
--- a/chromeos/dbus/flimflam_client_helper.h
+++ b/chromeos/dbus/flimflam_client_helper.h
@@ -82,6 +82,9 @@ class FlimflamClientHelper {
// DEPRECATED DO NOT USE: Calls a method without results.
bool CallVoidMethodAndBlock(dbus::MethodCall* method_call);
+ // DEPRECATED DO NOT USE: Calls a method with an object path result.
+ dbus::ObjectPath CallObjectPathMethodAndBlock(dbus::MethodCall* method_call);
+
// DEPRECATED DO NOT USE: Calls a method with a dictionary value result.
// The caller is responsible to delete the result.
// This method returns NULL when method call fails.
diff --git a/chromeos/dbus/flimflam_device_client.cc b/chromeos/dbus/flimflam_device_client.cc
index 18cf97f..bc57475 100644
--- a/chromeos/dbus/flimflam_device_client.cc
+++ b/chromeos/dbus/flimflam_device_client.cc
@@ -49,6 +49,15 @@ class FlimflamDeviceClientImpl : public FlimflamDeviceClient {
}
// FlimflamProfileClient override.
+ virtual base::DictionaryValue* CallGetPropertiesAndBlock(
+ const dbus::ObjectPath& device_path) OVERRIDE {
+ dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
+ flimflam::kGetPropertiesFunction);
+ return GetHelper(device_path)->CallDictionaryValueMethodAndBlock(
+ &method_call);
+ }
+
+ // FlimflamProfileClient override.
virtual void ProposeScan(const dbus::ObjectPath& device_path,
const VoidCallback& callback) OVERRIDE {
dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
@@ -92,6 +101,17 @@ class FlimflamDeviceClientImpl : public FlimflamDeviceClient {
}
// FlimflamProfileClient override.
+ virtual dbus::ObjectPath CallAddIPConfigAndBlock(
+ const dbus::ObjectPath& device_path,
+ const std::string& method) OVERRIDE {
+ dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
+ flimflam::kAddIPConfigFunction);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(method);
+ return GetHelper(device_path)->CallObjectPathMethodAndBlock(&method_call);
+ }
+
+ // FlimflamProfileClient override.
virtual void RequirePin(const dbus::ObjectPath& device_path,
const std::string& pin,
bool require,
@@ -203,6 +223,12 @@ class FlimflamDeviceClientStubImpl : public FlimflamDeviceClient {
callback));
}
+ // FlimflamDeviceClient override.
+ virtual base::DictionaryValue* CallGetPropertiesAndBlock(
+ const dbus::ObjectPath& device_path) OVERRIDE {
+ return new base::DictionaryValue;
+ }
+
// FlimflamProfileClient override.
virtual void ProposeScan(const dbus::ObjectPath& device_path,
const VoidCallback& callback) OVERRIDE {
@@ -235,6 +261,13 @@ class FlimflamDeviceClientStubImpl : public FlimflamDeviceClient {
}
// FlimflamDeviceClient override.
+ virtual dbus::ObjectPath CallAddIPConfigAndBlock(
+ const dbus::ObjectPath& device_path,
+ const std::string& method) OVERRIDE {
+ return dbus::ObjectPath();
+ }
+
+ // FlimflamDeviceClient override.
virtual void RequirePin(const dbus::ObjectPath& device_path,
const std::string& pin,
bool require,
diff --git a/chromeos/dbus/flimflam_device_client.h b/chromeos/dbus/flimflam_device_client.h
index 722f0c3..451a031 100644
--- a/chromeos/dbus/flimflam_device_client.h
+++ b/chromeos/dbus/flimflam_device_client.h
@@ -60,6 +60,14 @@ class CHROMEOS_EXPORT FlimflamDeviceClient {
virtual void GetProperties(const dbus::ObjectPath& device_path,
const DictionaryValueCallback& callback) = 0;
+ // DEPRECATED DO NOT USE: Calls GetProperties method and blocks until the
+ // method call finishes. The caller is responsible to delete the result.
+ // Thie method returns NULL when method call fails.
+ //
+ // TODO(hashimoto): Refactor CrosGetDeviceNetworkList and remove this method.
+ virtual base::DictionaryValue* CallGetPropertiesAndBlock(
+ const dbus::ObjectPath& device_path) = 0;
+
// Calls ProposeScan method.
// |callback| is called after the method call finishes.
virtual void ProposeScan(const dbus::ObjectPath& device_path,
@@ -84,6 +92,15 @@ class CHROMEOS_EXPORT FlimflamDeviceClient {
const std::string& method,
const ObjectPathCallback& callback) = 0;
+ // DEPRECATED DO NOT USE: Calls AddIPConfig method and blocks until the method
+ // call finishes.
+ // This method returns an empty path when method call fails.
+ //
+ // TODO(hashimoto): Refactor CrosAddIPConfig and remove this method.
+ virtual dbus::ObjectPath CallAddIPConfigAndBlock(
+ const dbus::ObjectPath& device_path,
+ const std::string& method) = 0;
+
// Calls RequirePin method.
// |callback| is called after the method call finishes.
virtual void RequirePin(const dbus::ObjectPath& device_path,
diff --git a/chromeos/dbus/flimflam_device_client_unittest.cc b/chromeos/dbus/flimflam_device_client_unittest.cc
index 516ceb4..201abb3 100644
--- a/chromeos/dbus/flimflam_device_client_unittest.cc
+++ b/chromeos/dbus/flimflam_device_client_unittest.cc
@@ -121,6 +121,34 @@ TEST_F(FlimflamDeviceClientTest, GetProperties) {
message_loop_.RunAllPending();
}
+TEST_F(FlimflamDeviceClientTest, CallGetPropertiesAndBlock) {
+ const bool kValue = true;
+ // Create response.
+ scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
+ dbus::MessageWriter writer(response.get());
+ dbus::MessageWriter array_writer(NULL);
+ writer.OpenArray("{sv}", &array_writer);
+ dbus::MessageWriter entry_writer(NULL);
+ array_writer.OpenDictEntry(&entry_writer);
+ entry_writer.AppendString(flimflam::kCellularAllowRoamingProperty);
+ entry_writer.AppendVariantOfBool(kValue);
+ array_writer.CloseContainer(&entry_writer);
+ writer.CloseContainer(&array_writer);
+
+ // Set expectations.
+ base::DictionaryValue value;
+ value.SetWithoutPathExpansion(flimflam::kCellularAllowRoamingProperty,
+ base::Value::CreateBooleanValue(kValue));
+ PrepareForMethodCall(flimflam::kGetPropertiesFunction,
+ base::Bind(&ExpectNoArgument),
+ response.get());
+ // Call method.
+ scoped_ptr<base::DictionaryValue> result(
+ client_->CallGetPropertiesAndBlock(dbus::ObjectPath(kExampleDevicePath)));
+ ASSERT_TRUE(result.get());
+ EXPECT_TRUE(result->Equals(&value));
+}
+
TEST_F(FlimflamDeviceClientTest, ProposeScan) {
// Create response.
scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
@@ -174,6 +202,42 @@ TEST_F(FlimflamDeviceClientTest, ClearProperty) {
message_loop_.RunAllPending();
}
+TEST_F(FlimflamDeviceClientTest, AddIPConfig) {
+ const dbus::ObjectPath expected_result("/result/path");
+ // Create response.
+ scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
+ dbus::MessageWriter writer(response.get());
+ writer.AppendObjectPath(expected_result);
+
+ // Set expectations.
+ PrepareForMethodCall(flimflam::kAddIPConfigFunction,
+ base::Bind(&ExpectStringArgument, flimflam::kTypeDHCP),
+ response.get());
+ // Call method.
+ client_->AddIPConfig(dbus::ObjectPath(kExampleDevicePath),
+ flimflam::kTypeDHCP,
+ base::Bind(&ExpectObjectPathResult, expected_result));
+ // Run the message loop.
+ message_loop_.RunAllPending();
+}
+
+TEST_F(FlimflamDeviceClientTest, CallAddIPConfigAndBlock) {
+ const dbus::ObjectPath expected_result("/result/path");
+ // Create response.
+ scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
+ dbus::MessageWriter writer(response.get());
+ writer.AppendObjectPath(expected_result);
+
+ // Set expectations.
+ PrepareForMethodCall(flimflam::kAddIPConfigFunction,
+ base::Bind(&ExpectStringArgument, flimflam::kTypeDHCP),
+ response.get());
+ // Call method.
+ const dbus::ObjectPath result = client_->CallAddIPConfigAndBlock(
+ dbus::ObjectPath(kExampleDevicePath), flimflam::kTypeDHCP);
+ EXPECT_EQ(expected_result, result);
+}
+
TEST_F(FlimflamDeviceClientTest, RequirePin) {
const char kPin[] = "123456";
const bool kRequired = true;
diff --git a/chromeos/dbus/mock_flimflam_device_client.h b/chromeos/dbus/mock_flimflam_device_client.h
index 278c1c8..0360000 100644
--- a/chromeos/dbus/mock_flimflam_device_client.h
+++ b/chromeos/dbus/mock_flimflam_device_client.h
@@ -24,6 +24,8 @@ class MockFlimflamDeviceClient : public FlimflamDeviceClient {
void(const dbus::ObjectPath& device_path));
MOCK_METHOD2(GetProperties, void(const dbus::ObjectPath& device_path,
const DictionaryValueCallback& callback));
+ MOCK_METHOD1(CallGetPropertiesAndBlock,
+ base::DictionaryValue*(const dbus::ObjectPath& device_path));
MOCK_METHOD2(ProposeScan, void(const dbus::ObjectPath& device_path,
const VoidCallback& callback));
MOCK_METHOD4(SetProperty, void(const dbus::ObjectPath& device_path,
@@ -36,6 +38,9 @@ class MockFlimflamDeviceClient : public FlimflamDeviceClient {
MOCK_METHOD3(AddIPConfig, void(const dbus::ObjectPath& device_path,
const std::string& method,
const ObjectPathCallback& callback));
+ MOCK_METHOD2(CallAddIPConfigAndBlock,
+ dbus::ObjectPath(const dbus::ObjectPath& device_path,
+ const std::string& method));
MOCK_METHOD4(RequirePin, void(const dbus::ObjectPath& device_path,
const std::string& pin,
bool require,