summaryrefslogtreecommitdiffstats
path: root/chromeos/dbus
diff options
context:
space:
mode:
authorharuki@chromium.org <haruki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-09 09:23:42 +0000
committerharuki@chromium.org <haruki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-09 09:23:42 +0000
commitc5c1bb9becb7c2888b39aefdc644b1597f3fb6ed (patch)
tree745527c26754c064dc271b6a0d42b97a34ed6331 /chromeos/dbus
parent4d23fa7767480ed29714f2662a4fb0dbf7510e0e (diff)
downloadchromium_src-c5c1bb9becb7c2888b39aefdc644b1597f3fb6ed.zip
chromium_src-c5c1bb9becb7c2888b39aefdc644b1597f3fb6ed.tar.gz
chromium_src-c5c1bb9becb7c2888b39aefdc644b1597f3fb6ed.tar.bz2
dbus: Add FakeGsmSMSClient and replace the stub.
BUG=234498 TEST=trybots R=satorux@chromium.org Review URL: https://codereview.chromium.org/14949007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199173 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/dbus')
-rw-r--r--chromeos/dbus/fake_gsm_sms_client.cc112
-rw-r--r--chromeos/dbus/fake_gsm_sms_client.h70
-rw-r--r--chromeos/dbus/gsm_sms_client.cc125
-rw-r--r--chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc5
-rw-r--r--chromeos/dbus/mock_dbus_thread_manager_without_gmock.h6
5 files changed, 198 insertions, 120 deletions
diff --git a/chromeos/dbus/fake_gsm_sms_client.cc b/chromeos/dbus/fake_gsm_sms_client.cc
new file mode 100644
index 0000000..8c63434
--- /dev/null
+++ b/chromeos/dbus/fake_gsm_sms_client.cc
@@ -0,0 +1,112 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/bind.h"
+#include "base/message_loop.h"
+#include "chromeos/dbus/fake_gsm_sms_client.h"
+
+namespace chromeos {
+
+FakeGsmSMSClient::FakeGsmSMSClient()
+ : test_index_(-1),
+ sms_test_message_switch_present_(false),
+ weak_ptr_factory_(this) {
+ test_messages_.push_back("Test Message 0");
+ test_messages_.push_back("Test Message 1");
+ test_messages_.push_back("Test a relatively long message 2");
+ test_messages_.push_back("Test a very, the quick brown fox jumped"
+ " over the lazy dog, long message 3");
+ test_messages_.push_back("Test Message 4");
+ test_messages_.push_back("Test Message 5");
+ test_messages_.push_back("Test Message 6");
+}
+
+FakeGsmSMSClient::~FakeGsmSMSClient() {}
+
+void FakeGsmSMSClient::SetSmsReceivedHandler(
+ const std::string& service_name,
+ const dbus::ObjectPath& object_path,
+ const SmsReceivedHandler& handler) {
+ handler_ = handler;
+}
+
+void FakeGsmSMSClient::ResetSmsReceivedHandler(
+ const std::string& service_name,
+ const dbus::ObjectPath& object_path) {
+ handler_.Reset();
+}
+
+void FakeGsmSMSClient::Delete(const std::string& service_name,
+ const dbus::ObjectPath& object_path,
+ uint32 index,
+ const DeleteCallback& callback) {
+ message_list_.Remove(index, NULL);
+ callback.Run();
+}
+
+void FakeGsmSMSClient::Get(const std::string& service_name,
+ const dbus::ObjectPath& object_path,
+ uint32 index,
+ const GetCallback& callback) {
+ base::DictionaryValue* dictionary = NULL;
+ if (message_list_.GetDictionary(index, &dictionary)) {
+ callback.Run(*dictionary);
+ return;
+ }
+ base::DictionaryValue empty_dictionary;
+ callback.Run(empty_dictionary);
+}
+
+void FakeGsmSMSClient::List(const std::string& service_name,
+ const dbus::ObjectPath& object_path,
+ const ListCallback& callback) {
+ callback.Run(message_list_);
+}
+
+void FakeGsmSMSClient::RequestUpdate(const std::string& service_name,
+ const dbus::ObjectPath& object_path) {
+ if (!sms_test_message_switch_present_)
+ return;
+
+ if (test_index_ >= 0)
+ return;
+ test_index_ = 0;
+ // Call PushTestMessageChain asynchronously so that the handler_ callback
+ // does not get called from the update request.
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&FakeGsmSMSClient::PushTestMessageChain,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void FakeGsmSMSClient::PushTestMessageChain() {
+ if (PushTestMessage())
+ PushTestMessageDelayed();
+}
+
+void FakeGsmSMSClient::PushTestMessageDelayed() {
+ const int kSmsMessageDelaySeconds = 5;
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&FakeGsmSMSClient::PushTestMessageChain,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::TimeDelta::FromSeconds(kSmsMessageDelaySeconds));
+}
+
+bool FakeGsmSMSClient::PushTestMessage() {
+ if (test_index_ >= static_cast<int>(test_messages_.size()))
+ return false;
+ base::DictionaryValue* message = new base::DictionaryValue;
+ message->SetString("number", "000-000-0000");
+ message->SetString("text", test_messages_[test_index_]);
+ message->SetInteger("index", test_index_);
+ int msg_index = message_list_.GetSize();
+ message_list_.Append(message);
+ if (!handler_.is_null())
+ handler_.Run(msg_index, true);
+ ++test_index_;
+ return true;
+}
+
+} // namespace chromeos
diff --git a/chromeos/dbus/fake_gsm_sms_client.h b/chromeos/dbus/fake_gsm_sms_client.h
new file mode 100644
index 0000000..1a846ee
--- /dev/null
+++ b/chromeos/dbus/fake_gsm_sms_client.h
@@ -0,0 +1,70 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_DBUS_FAKE_GSM_SMS_CLIENT_H_
+#define CHROMEOS_DBUS_FAKE_GSM_SMS_CLIENT_H_
+
+#include <string>
+
+#include "base/memory/weak_ptr.h"
+#include "base/values.h"
+#include "chromeos/dbus/gsm_sms_client.h"
+#include "dbus/object_path.h"
+
+namespace chromeos {
+
+// A fake implementation of GsmSMSClient used for tests.
+class FakeGsmSMSClient : public GsmSMSClient {
+ public:
+ FakeGsmSMSClient();
+ virtual ~FakeGsmSMSClient();
+
+ // GsmSMSClient overrides.
+ virtual void SetSmsReceivedHandler(const std::string& service_name,
+ const dbus::ObjectPath& object_path,
+ const SmsReceivedHandler& handler)
+ OVERRIDE;
+ virtual void ResetSmsReceivedHandler(const std::string& service_name,
+ const dbus::ObjectPath& object_path)
+ OVERRIDE;
+ virtual void Delete(const std::string& service_name,
+ const dbus::ObjectPath& object_path,
+ uint32 index,
+ const DeleteCallback& callback) OVERRIDE;
+ virtual void Get(const std::string& service_name,
+ const dbus::ObjectPath& object_path,
+ uint32 index,
+ const GetCallback& callback) OVERRIDE;
+ virtual void List(const std::string& service_name,
+ const dbus::ObjectPath& object_path,
+ const ListCallback& callback) OVERRIDE;
+ virtual void RequestUpdate(const std::string& service_name,
+ const dbus::ObjectPath& object_path) OVERRIDE;
+
+ // Sets if the command line switch for test is present. RequestUpdate()
+ // changes its behavior depending on the switch.
+ void set_sms_test_message_switch_present(bool is_present) {
+ sms_test_message_switch_present_ = is_present;
+ }
+
+ private:
+ void PushTestMessageChain();
+ void PushTestMessageDelayed();
+ bool PushTestMessage();
+
+ int test_index_;
+ std::vector<std::string> test_messages_;
+ base::ListValue message_list_;
+ SmsReceivedHandler handler_;
+
+ bool sms_test_message_switch_present_;
+
+ base::WeakPtrFactory<FakeGsmSMSClient> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeGsmSMSClient);
+};
+
+} // namespace chromeos
+
+#endif // CHROMEOS_DBUS_FAKE_GSM_SMS_CLIENT_H_
diff --git a/chromeos/dbus/gsm_sms_client.cc b/chromeos/dbus/gsm_sms_client.cc
index 07e8479..1ac1e83 100644
--- a/chromeos/dbus/gsm_sms_client.cc
+++ b/chromeos/dbus/gsm_sms_client.cc
@@ -16,6 +16,7 @@
#include "base/stl_util.h"
#include "base/values.h"
#include "chromeos/chromeos_switches.h"
+#include "chromeos/dbus/fake_gsm_sms_client.h"
#include "dbus/bus.h"
#include "dbus/message.h"
#include "dbus/object_proxy.h"
@@ -236,123 +237,6 @@ class GsmSMSClientImpl : public GsmSMSClient {
DISALLOW_COPY_AND_ASSIGN(GsmSMSClientImpl);
};
-// A stub implementaion of GsmSMSClient.
-class GsmSMSClientStubImpl : public GsmSMSClient {
- public:
- GsmSMSClientStubImpl() : test_index_(-1), weak_ptr_factory_(this) {
- test_messages_.push_back("Test Message 0");
- test_messages_.push_back("Test Message 1");
- test_messages_.push_back("Test a relatively long message 2");
- test_messages_.push_back("Test a very, the quick brown fox jumped"
- " over the lazy dog, long message 3");
- test_messages_.push_back("Test Message 4");
- test_messages_.push_back("Test Message 5");
- test_messages_.push_back("Test Message 6");
- }
-
- virtual ~GsmSMSClientStubImpl() {}
-
- // GsmSMSClient override.
- virtual void SetSmsReceivedHandler(
- const std::string& service_name,
- const dbus::ObjectPath& object_path,
- const SmsReceivedHandler& handler) OVERRIDE {
- handler_ = handler;
- }
-
- // GsmSMSClient override.
- virtual void ResetSmsReceivedHandler(
- const std::string& service_name,
- const dbus::ObjectPath& object_path) OVERRIDE {
- handler_.Reset();
- }
-
- // GsmSMSClient override.
- virtual void Delete(const std::string& service_name,
- const dbus::ObjectPath& object_path,
- uint32 index,
- const DeleteCallback& callback) OVERRIDE {
- message_list_.Remove(index, NULL);
- callback.Run();
- }
-
- // GsmSMSClient override.
- virtual void Get(const std::string& service_name,
- const dbus::ObjectPath& object_path,
- uint32 index,
- const GetCallback& callback) OVERRIDE {
- base::DictionaryValue* dictionary = NULL;
- if (message_list_.GetDictionary(index, &dictionary)) {
- callback.Run(*dictionary);
- return;
- }
- base::DictionaryValue empty_dictionary;
- callback.Run(empty_dictionary);
- }
-
- // GsmSMSClient override.
- virtual void List(const std::string& service_name,
- const dbus::ObjectPath& object_path,
- const ListCallback& callback) OVERRIDE {
- callback.Run(message_list_);
- }
-
- // GsmSMSClient override.
- virtual void RequestUpdate(const std::string& service_name,
- const dbus::ObjectPath& object_path) OVERRIDE {
- if (!CommandLine::ForCurrentProcess()->HasSwitch(
- chromeos::switches::kSmsTestMessages))
- return;
- if (test_index_ >= 0)
- return;
- test_index_ = 0;
- // Call PushTestMessageChain asynchronously so that the handler_ callback
- // does not get called from the update request.
- MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(&GsmSMSClientStubImpl::PushTestMessageChain,
- weak_ptr_factory_.GetWeakPtr()));
- }
-
- private:
- void PushTestMessageChain() {
- if (PushTestMessage())
- PushTestMessageDelayed();
- }
-
- void PushTestMessageDelayed() {
- const int kSmsMessageDelaySeconds = 5;
- MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- base::Bind(&GsmSMSClientStubImpl::PushTestMessageChain,
- weak_ptr_factory_.GetWeakPtr()),
- base::TimeDelta::FromSeconds(kSmsMessageDelaySeconds));
- }
-
- bool PushTestMessage() {
- if (test_index_ >= static_cast<int>(test_messages_.size()))
- return false;
- base::DictionaryValue* message = new base::DictionaryValue;
- message->SetString("number", "000-000-0000");
- message->SetString("text", test_messages_[test_index_]);
- message->SetInteger("index", test_index_);
- int msg_index = message_list_.GetSize();
- message_list_.Append(message);
- if (!handler_.is_null())
- handler_.Run(msg_index, true);
- ++test_index_;
- return true;
- }
-
- int test_index_;
- std::vector<std::string> test_messages_;
- base::ListValue message_list_;
- SmsReceivedHandler handler_;
- base::WeakPtrFactory<GsmSMSClientStubImpl> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(GsmSMSClientStubImpl);
-};
-
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -368,7 +252,12 @@ GsmSMSClient* GsmSMSClient::Create(DBusClientImplementationType type,
if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
return new GsmSMSClientImpl(bus);
DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
- return new GsmSMSClientStubImpl();
+
+ FakeGsmSMSClient* fake = new FakeGsmSMSClient();
+ fake->set_sms_test_message_switch_present(
+ CommandLine::ForCurrentProcess()->HasSwitch(
+ chromeos::switches::kSmsTestMessages));
+ return fake;
}
} // namespace chromeos
diff --git a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc
index 4658db9..11f98c1 100644
--- a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc
+++ b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc
@@ -15,6 +15,7 @@
#include "chromeos/dbus/fake_bluetooth_profile_manager_client.h"
#include "chromeos/dbus/fake_cros_disks_client.h"
#include "chromeos/dbus/fake_cryptohome_client.h"
+#include "chromeos/dbus/fake_gsm_sms_client.h"
#include "chromeos/dbus/fake_image_burner_client.h"
#include "chromeos/dbus/fake_old_bluetooth_adapter_client.h"
#include "chromeos/dbus/fake_old_bluetooth_device_client.h"
@@ -43,6 +44,7 @@ MockDBusThreadManagerWithoutGMock::MockDBusThreadManagerWithoutGMock()
new FakeBluetoothProfileManagerClient()),
fake_cros_disks_client_(new FakeCrosDisksClient),
fake_cryptohome_client_(new FakeCryptohomeClient),
+ fake_gsm_sms_client_(new FakeGsmSMSClient),
fake_image_burner_client_(new FakeImageBurnerClient),
fake_session_manager_client_(new FakeSessionManagerClient),
fake_shill_manager_client_(new FakeShillManagerClient),
@@ -197,8 +199,7 @@ ShillServiceClient*
}
GsmSMSClient* MockDBusThreadManagerWithoutGMock::GetGsmSMSClient() {
- NOTIMPLEMENTED();
- return NULL;
+ return fake_gsm_sms_client_.get();
}
ImageBurnerClient* MockDBusThreadManagerWithoutGMock::GetImageBurnerClient() {
diff --git a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h
index 84f82ce..effa2cb 100644
--- a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h
+++ b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h
@@ -26,6 +26,7 @@ class FakeBluetoothInputClient;
class FakeBluetoothProfileManagerClient;
class FakeCrosDisksClient;
class FakeCryptohomeClient;
+class FakeGsmSMSClient;
class FakeOldBluetoothAdapterClient;
class FakeOldBluetoothDeviceClient;
class FakeOldBluetoothManagerClient;
@@ -133,6 +134,10 @@ class MockDBusThreadManagerWithoutGMock : public DBusThreadManager {
return fake_cryptohome_client_.get();
}
+ FakeGsmSMSClient* fake_gsm_sms_client() {
+ return fake_gsm_sms_client_.get();
+ }
+
FakeImageBurnerClient* fake_image_burner_client() {
return fake_image_burner_client_.get();
}
@@ -200,6 +205,7 @@ class MockDBusThreadManagerWithoutGMock : public DBusThreadManager {
fake_bluetooth_profile_manager_client_;
scoped_ptr<FakeCrosDisksClient> fake_cros_disks_client_;
scoped_ptr<FakeCryptohomeClient> fake_cryptohome_client_;
+ scoped_ptr<FakeGsmSMSClient> fake_gsm_sms_client_;
scoped_ptr<FakeImageBurnerClient> fake_image_burner_client_;
scoped_ptr<FakeSessionManagerClient> fake_session_manager_client_;
scoped_ptr<FakeShillManagerClient> fake_shill_manager_client_;