1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chromeos/dbus/fake_modem_messaging_client.h" 6 7#include <string> 8#include <vector> 9 10#include "base/callback.h" 11#include "base/logging.h" 12#include "dbus/object_path.h" 13 14namespace chromeos { 15 16FakeModemMessagingClient::FakeModemMessagingClient() {} 17FakeModemMessagingClient::~FakeModemMessagingClient() {} 18 19void FakeModemMessagingClient::Init(dbus::Bus* bus) {} 20 21void FakeModemMessagingClient::SetSmsReceivedHandler( 22 const std::string& service_name, 23 const dbus::ObjectPath& object_path, 24 const SmsReceivedHandler& handler) { 25 sms_received_handler_ = handler; 26} 27 28void FakeModemMessagingClient::ResetSmsReceivedHandler( 29 const std::string& service_name, 30 const dbus::ObjectPath& object_path) { 31 sms_received_handler_.Reset(); 32} 33 34void FakeModemMessagingClient::Delete(const std::string& service_name, 35 const dbus::ObjectPath& object_path, 36 const dbus::ObjectPath& sms_path, 37 const DeleteCallback& callback) { 38 std::vector<dbus::ObjectPath>::iterator it( 39 find(message_paths_.begin(), message_paths_.end(), sms_path)); 40 if (it != message_paths_.end()) 41 message_paths_.erase(it); 42 callback.Run(); 43} 44 45void FakeModemMessagingClient::List(const std::string& service_name, 46 const dbus::ObjectPath& object_path, 47 const ListCallback& callback) { 48 // This entire FakeModemMessagingClient is for testing. 49 // Calling List with |service_name| equal to "AddSMS" allows unit 50 // tests to confirm that the sms_received_handler is functioning. 51 if (service_name == "AddSMS") { 52 std::vector<dbus::ObjectPath> no_paths; 53 const dbus::ObjectPath kSmsPath("/SMS/0"); 54 message_paths_.push_back(kSmsPath); 55 if (!sms_received_handler_.is_null()) 56 sms_received_handler_.Run(kSmsPath, true); 57 callback.Run(no_paths); 58 } else { 59 callback.Run(message_paths_); 60 } 61} 62 63} // namespace chromeos 64