@@ -82,6 +82,7 @@ class FakeBluetooth {
82
82
this . fake_bluetooth_ptr_ = new bluetooth . mojom . FakeBluetoothPtr ( ) ;
83
83
Mojo . bindInterface ( bluetooth . mojom . FakeBluetooth . name ,
84
84
mojo . makeRequest ( this . fake_bluetooth_ptr_ ) . handle , 'process' ) ;
85
+ this . fake_central_ = null ;
85
86
}
86
87
87
88
// Set it to indicate whether the platform supports BLE. For example,
@@ -105,12 +106,16 @@ class FakeBluetooth {
105
106
// See Bluetooth 4.2 Vol 3 Part C 2.2.2 "Roles when Operating over an
106
107
// LE Physical Transport".
107
108
async simulateCentral ( { state} ) {
109
+ if ( this . fake_central_ )
110
+ throw 'simulateCentral() should only be called once' ;
111
+
108
112
await this . setLESupported ( true ) ;
109
113
110
114
let { fakeCentral : fake_central_ptr } =
111
115
await this . fake_bluetooth_ptr_ . simulateCentral (
112
116
toMojoCentralState ( state ) ) ;
113
- return new FakeCentral ( fake_central_ptr ) ;
117
+ this . fake_central_ = new FakeCentral ( fake_central_ptr ) ;
118
+ return this . fake_central_ ;
114
119
}
115
120
116
121
// Returns true if there are no pending responses.
@@ -202,6 +207,16 @@ class FakeCentral {
202
207
return this . fetchOrCreatePeripheral_ ( scanResult . deviceAddress ) ;
203
208
}
204
209
210
+ // Simulates a change in the central device described by |state|. For example,
211
+ // setState('powered-off') can be used to simulate the central device powering
212
+ // off.
213
+ //
214
+ // This method should be used for any central state changes after
215
+ // simulateCentral() has been called to create a FakeCentral object.
216
+ async setState ( state ) {
217
+ await this . fake_central_ptr_ . setState ( toMojoCentralState ( state ) ) ;
218
+ }
219
+
205
220
// Create a fake_peripheral object from the given address.
206
221
fetchOrCreatePeripheral_ ( address ) {
207
222
let peripheral = this . peripherals_ . get ( address ) ;
0 commit comments