summaryrefslogtreecommitdiffstats
path: root/chromeos/dbus/fake_gsm_sms_client.h
blob: 0df9c120e022c59fa0c66f63080e28fcf8502e9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// 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 <stdint.h>

#include <string>

#include "base/macros.h"
#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 CHROMEOS_EXPORT FakeGsmSMSClient : public GsmSMSClient {
 public:
  FakeGsmSMSClient();
  ~FakeGsmSMSClient() override;

  // GsmSMSClient overrides
  void Init(dbus::Bus* bus) override;
  void SetSmsReceivedHandler(const std::string& service_name,
                             const dbus::ObjectPath& object_path,
                             const SmsReceivedHandler& handler) override;
  void ResetSmsReceivedHandler(const std::string& service_name,
                               const dbus::ObjectPath& object_path) override;
  void Delete(const std::string& service_name,
              const dbus::ObjectPath& object_path,
              uint32_t index,
              const DeleteCallback& callback) override;
  void Get(const std::string& service_name,
           const dbus::ObjectPath& object_path,
           uint32_t index,
           const GetCallback& callback) override;
  void List(const std::string& service_name,
            const dbus::ObjectPath& object_path,
            const ListCallback& callback) override;
  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_