// Copyright 2014 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 "device/bluetooth/test/mock_bluetooth_gatt_notify_session.h" #include "device/bluetooth/test/mock_bluetooth_adapter.h" #include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h" using testing::Return; namespace device { MockBluetoothGattNotifySession::MockBluetoothGattNotifySession( const std::string& characteristic_identifier) { ON_CALL(*this, GetCharacteristicIdentifier()) .WillByDefault(Return(characteristic_identifier)); ON_CALL(*this, IsActive()).WillByDefault(Return(true)); } MockBluetoothGattNotifySession::~MockBluetoothGattNotifySession() { } void MockBluetoothGattNotifySession::StartTestNotifications( MockBluetoothAdapter* adapter, MockBluetoothGattCharacteristic* characteristic, const std::vector& value) { test_notifications_timer_.Start( FROM_HERE, base::TimeDelta::FromMilliseconds(10), base::Bind(&MockBluetoothGattNotifySession::DoNotify, // base::Timer guarantees it won't call back after its // destructor starts. base::Unretained(this), base::Unretained(adapter), characteristic, value)); } void MockBluetoothGattNotifySession::StopTestNotifications() { test_notifications_timer_.Stop(); } void MockBluetoothGattNotifySession::DoNotify( MockBluetoothAdapter* adapter, MockBluetoothGattCharacteristic* characteristic, const std::vector& value) { FOR_EACH_OBSERVER( BluetoothAdapter::Observer, adapter->GetObservers(), GattCharacteristicValueChanged(adapter, characteristic, value)); } } // namespace device