Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/resources/bluetooth/web-bluetooth-test.js |
| diff --git a/third_party/WebKit/LayoutTests/resources/bluetooth/web-bluetooth-test.js b/third_party/WebKit/LayoutTests/resources/bluetooth/web-bluetooth-test.js |
| index 4ff126f700c4495d0dc470b3101db2cc936a94bf..ad490b037c60f60f028b9ba1241d6e0315b6ec18 100644 |
| --- a/third_party/WebKit/LayoutTests/resources/bluetooth/web-bluetooth-test.js |
| +++ b/third_party/WebKit/LayoutTests/resources/bluetooth/web-bluetooth-test.js |
| @@ -26,9 +26,26 @@ |
| return mojo_; |
| } |
| + async function toMojoCentralState(state) { |
| + let mojo = await loadFakeBluetoothInterfaces(); |
| + |
| + let mojo_central_state; |
| + switch (state) { |
| + case 'absent': |
| + return mojo.CentralState.ABSENT; |
| + case 'powered-off': |
| + return mojo.CentralState.POWERED_OFF; |
| + case 'powered-on': |
| + return mojo.CentralState.POWERED_ON; |
| + default: |
| + throw `Unsupported value ${state} for state.`; |
| + } |
| + } |
| + |
| class FakeBluetooth { |
| constructor() { |
| this.fake_bluetooth_ptr_ = undefined; |
| + this.fake_central_ = undefined; |
| } |
| // Set it to indicate whether the platform supports BLE. For example, |
| @@ -73,28 +90,16 @@ |
| await setBluetoothFakeAdapter(''); |
| await this.setLESupported(true); |
| - let mojo = await loadFakeBluetoothInterfaces(); |
| - |
| - let mojo_manager_state; |
| - switch (state) { |
| - case 'absent': |
| - mojo_manager_state = mojo.CentralState.ABSENT; |
| - break; |
| - case 'powered-off': |
| - mojo_manager_state = mojo.CentralState.POWERED_OFF; |
| - break; |
| - case 'powered-on': |
| - mojo_manager_state = mojo.CentralState.POWERED_ON; |
| - break; |
| - default: |
| - throw `Unsupported value ${state} for state.`; |
| + if (this.fake_central_ === undefined) { |
|
scheib
2017/05/09 23:33:54
... continued from previous comment. This logic se
ortuno
2017/05/10 06:32:51
Yeah, I agree. It was a trade-off between convenie
|
| + let {fake_central:fake_central_ptr} = |
| + await (await this.getFakeBluetoothInterface_()).simulateCentral( |
| + await toMojoCentralState(state)); |
| + this.fake_central_ = new FakeCentral(fake_central_ptr); |
| + } else { |
| + await this.fake_central_.setState(state); |
| } |
| - let {fake_central:fake_central_ptr} = |
| - await (await this.getFakeBluetoothInterface_()).simulateCentral( |
| - mojo_manager_state); |
| - |
| - return new FakeCentral(fake_central_ptr); |
| + return this.fake_central_; |
| } |
| async getFakeBluetoothInterface_() { |
| @@ -120,17 +125,24 @@ |
| this.peripherals_ = new Map(); |
| } |
| - // Simulates a peripheral with |address| and |name| that has already |
| - // been connected to the system. If the peripheral existed already it |
| - // updates its name. |
| + // Simulates a peripheral with |address|, |name| and |known_service_uuids| |
|
scheib
2017/05/09 23:33:54
Describe that array members of known_service_uuids
ortuno
2017/05/10 06:32:51
Done.
|
| + // that has already been connected to the system. If the peripheral existed |
| + // already it updates its name and known UUIDs. |
| // |
| // Platforms offer methods to retrieve devices that have already been |
| - // connected to the system or weren't connected through the UA e.g. a |
| - // user connected a peripheral through the system's settings. This method is |
| + // connected to the system or weren't connected through the UA e.g. a user |
| + // connected a peripheral through the system's settings. This method is |
| // intended to simulate peripherals that those methods would return. |
| - async simulatePreconnectedPeripheral({address, name}) { |
| + async simulatePreconnectedPeripheral({ |
| + address, name, knownServiceUUIDs = []}) { |
| + |
| + // Canonicalize and convert to mojo UUIDs. |
| + knownServiceUUIDs.forEach((val, i, arr) => { |
| + knownServiceUUIDs[i] = {uuid: BluetoothUUID.getService(val)}; |
| + }); |
| + |
| await this.fake_central_ptr_.simulatePreconnectedPeripheral( |
| - address, name); |
| + address, name, knownServiceUUIDs); |
| let peripheral = this.peripherals_.get(address); |
| if (peripheral === undefined) { |
| @@ -140,6 +152,10 @@ |
| return peripheral; |
| } |
| + |
| + async setState(state) { |
| + await this.fake_central_ptr_.setState(await toMojoCentralState(state)); |
| + } |
| } |
| class FakePeripheral { |