| 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 eee28a3e18d1cc4748815f38276b702f755942a7..7fd297ea003dc779e6376faab3d023bffe31b66a 100644
|
| --- a/third_party/WebKit/LayoutTests/resources/bluetooth/web-bluetooth-test.js
|
| +++ b/third_party/WebKit/LayoutTests/resources/bluetooth/web-bluetooth-test.js
|
| @@ -15,7 +15,14 @@
|
| 'device/bluetooth/public/interfaces/test/fake_bluetooth.mojom'
|
| ]);
|
|
|
| - [mojo_.bindings, mojo_.FakeBluetooth] = mojo_.modules;
|
| + [mojo_.bindings, {
|
| + CentralState: mojo_.CentralState,
|
| + FakeBluetooth: mojo_.FakeBluetooth,
|
| + FakeBluetoothPtr: mojo_.FakeBluetoothPtr,
|
| + FakeCentral: mojo_.FakeCentral,
|
| + FakeCentralPtr: mojo_.FakeCentralPtr,
|
| + }] = mojo_.modules;
|
| +
|
| return mojo_;
|
| }
|
|
|
| @@ -33,6 +40,47 @@
|
| await (await this.getFakeBluetoothInterface_()).setLESupported(available);
|
| }
|
|
|
| + // Returns a promise that resolves with a FakeCentral that clients can use
|
| + // to simulate events that a device in the Central/Observer role would
|
| + // receive as well as monitor the operations performed by the device in the
|
| + // Central/Observer role.
|
| + // Calls sets LE as supported.
|
| + async simulateCentral({state}) {
|
| + // Call setBluetoothFakeAdapter() to clean up any fake adapters left over
|
| + // by legacy tests.
|
| + // Legacy tests that use setBluetoothFakeAdapter() sometimes fail to clean
|
| + // their fake adapter. This is not a problem for these tests because the
|
| + // next setBluetoothFakeAdapter() will clean it up anyway but it is a
|
| + // problem for the new tests that do not use setBluetoothFakeAdapter().
|
| + // TODO(crbug.com/569709): Remove once setBluetoothFakeAdapter is no
|
| + // longer used.
|
| + 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.`;
|
| + }
|
| +
|
| + let {fake_central:fake_central_ptr} =
|
| + await (await this.getFakeBluetoothInterface_()).simulateCentral(
|
| + mojo_manager_state);
|
| +
|
| + return new FakeCentral(fake_central_ptr);
|
| + }
|
| +
|
| async getFakeBluetoothInterface_() {
|
| if (typeof this.fake_bluetooth_ptr_ !== 'undefined') {
|
| return this.fake_bluetooth_ptr_;
|
| @@ -40,13 +88,21 @@
|
|
|
| let mojo = await loadFakeBluetoothInterfaces();
|
|
|
| - this.fake_bluetooth_ptr_ = new mojo.FakeBluetooth.FakeBluetoothPtr(
|
| - mojo.interfaces.getInterface(
|
| - mojo.FakeBluetooth.FakeBluetooth.name));
|
| + this.fake_bluetooth_ptr_ = new mojo.FakeBluetoothPtr(
|
| + mojo.interfaces.getInterface(mojo.FakeBluetooth.name));
|
|
|
| return this.fake_bluetooth_ptr_;
|
| }
|
| }
|
|
|
| + // FakeCentral allows clients to simulate events that a device in the
|
| + // Central/Observer role would receive as well as monitor the operations
|
| + // performed by the device in the Central/Observer role.
|
| + class FakeCentral {
|
| + constructor(fake_central_ptr) {
|
| + this.fake_central_ptr = fake_central_ptr;
|
| + }
|
| + }
|
| +
|
| navigator.bluetooth.test = new FakeBluetooth();
|
| })();
|
|
|