Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_DEVICE_H_ | 5 #ifndef DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_DEVICE_H_ |
| 6 #define DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_DEVICE_H_ | 6 #define DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_DEVICE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 // ON_CALL(*mock_device, GetGattServices)) | 109 // ON_CALL(*mock_device, GetGattServices)) |
| 110 // .WillByDefault(Invoke(*mock_device, | 110 // .WillByDefault(Invoke(*mock_device, |
| 111 // &MockBluetoothDevice::GetMockServices)); | 111 // &MockBluetoothDevice::GetMockServices)); |
| 112 void AddMockService(std::unique_ptr<MockBluetoothGattService> mock_device); | 112 void AddMockService(std::unique_ptr<MockBluetoothGattService> mock_device); |
| 113 std::vector<BluetoothRemoteGattService*> GetMockServices() const; | 113 std::vector<BluetoothRemoteGattService*> GetMockServices() const; |
| 114 BluetoothRemoteGattService* GetMockService( | 114 BluetoothRemoteGattService* GetMockService( |
| 115 const std::string& identifier) const; | 115 const std::string& identifier) const; |
| 116 | 116 |
| 117 void AddUUID(const BluetoothUUID& uuid) { uuids_.insert(uuid); } | 117 void AddUUID(const BluetoothUUID& uuid) { uuids_.insert(uuid); } |
| 118 | 118 |
| 119 // Functions to save and retrieve callbacks from this device. Useful when | |
| 120 // trying to run callbacks in response to other actions e.g. run a read | |
| 121 // value callback in response to a connection request. | |
| 122 // Appends callback to the end of the callbacks queue. | |
| 123 void PushPendingCallback(const base::Closure& callback); | |
| 124 // Returns true if there are any callbacks in the queue; false otherwise. | |
| 125 bool HasPendingCallback(); | |
| 126 // Pops and returns the first callback in the queue. | |
| 127 base::Closure PopPendingCallback(); | |
|
Jeffrey Yasskin
2016/10/22 01:02:06
Consider making this RunAllCallbacks() instead. If
ortuno
2016/10/24 01:52:33
Done. I also removed the HasPendingCallback functi
| |
| 128 | |
| 119 void SetConnected(bool connected) { connected_ = connected; } | 129 void SetConnected(bool connected) { connected_ = connected; } |
| 120 | 130 |
| 121 private: | 131 private: |
| 122 uint32_t bluetooth_class_; | 132 uint32_t bluetooth_class_; |
| 123 base::Optional<std::string> name_; | 133 base::Optional<std::string> name_; |
| 124 std::string address_; | 134 std::string address_; |
| 125 BluetoothDevice::UUIDSet uuids_; | 135 BluetoothDevice::UUIDSet uuids_; |
| 126 bool connected_; | 136 bool connected_; |
| 127 | 137 |
| 138 // Used by tests to save callbacks that will be run in the future. | |
| 139 std::queue<base::Closure> pending_callbacks_; | |
| 140 | |
| 128 ScopedVector<MockBluetoothGattService> mock_services_; | 141 ScopedVector<MockBluetoothGattService> mock_services_; |
| 129 }; | 142 }; |
| 130 | 143 |
| 131 } // namespace device | 144 } // namespace device |
| 132 | 145 |
| 133 #endif // DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_DEVICE_H_ | 146 #endif // DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_DEVICE_H_ |
| OLD | NEW |