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 d391827f227e120cff52f08b585481fc11e3d79f..1d8d50185f59d072331fad227fb752eed5686117 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_; |
| } |
| @@ -41,6 +48,44 @@ |
| }; |
| } |
| + // 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. |
| + 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(''); |
| + let mojo = await loadFakeBluetoothInterfaces(); |
| + |
| + let mojo_manager_state; |
| + switch (state) { |
| + case 'absent': |
| + mojo_manager_state = mojo.CentralState.ABSENT; |
| + break; |
| + case 'poweredoff': |
|
scheib
2017/05/02 03:26:59
poweredOff?
ortuno
2017/05/03 00:17:42
tldr; went with powered-off/powered-on
WebIDl "st
|
| + mojo_manager_state = mojo.CentralState.POWERED_OFF; |
| + break; |
| + case 'poweredon': |
| + 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_; |
| @@ -48,13 +93,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(); |
| })(); |