Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/resources/web-bluetooth-test.js |
| diff --git a/third_party/WebKit/LayoutTests/resources/web-bluetooth-test.js b/third_party/WebKit/LayoutTests/resources/web-bluetooth-test.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3be6c6f1d19ec57c655db3b15ffd47b9c55677e6 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/resources/web-bluetooth-test.js |
| @@ -0,0 +1,47 @@ |
| +(() => { |
| + let mojo_; |
| + let fake_bluetooth_; |
| + |
| + async function getFakeBluetooth() { |
| + if (typeof fake_bluetooth_ !== 'undefined') { |
| + return fake_bluetooth_; |
| + } |
| + |
| + if (typeof loadMojoModules === 'undefined') { |
| + throw 'Mojo is required for this API.' |
| + } |
| + |
| + mojo_ = await loadMojoModules('fakeBluetooth', [ |
| + 'mojo/public/js/bindings', |
|
scheib
2017/04/08 00:59:50
Maybe OK, but we don't seem to use mojo_.bindings
ortuno
2017/04/10 01:47:49
I tried to remove it and mojo_.FakeBluetooth.FakeB
|
| + 'device/bluetooth/public/interfaces/test/fake_bluetooth.mojom' |
| + ]); |
| + |
| + [mojo_.bindings, mojo_.FakeBluetooth] = mojo_.modules; |
| + |
| + fake_bluetooth_ = new mojo_.FakeBluetooth.FakeBluetoothPtr( |
| + mojo_.interfaces.getInterface( |
| + mojo_.FakeBluetooth.FakeBluetooth.name)); |
| + |
| + return fake_bluetooth_; |
| + } |
| + |
| + class FakeBluetooth { |
|
scheib
2017/04/08 00:59:50
The FakeBluetooth class implements the specified f
ortuno
2017/04/10 01:47:49
I feel as if I were implementing OO features using
|
| + constructor() { |
| + } |
| + |
| + async setLEAvailability(available) { |
| + if (typeof available !== 'boolean') throw 'Type Not Supported'; |
| + await (await getFakeBluetooth()).setLEAvailability(available); |
| + |
| + // TODO(crbug.com/569709): Remove once FakeBluetooth.setLEAvailability is |
| + // implemented in the browser. |
| + navigator.bluetooth.requestDevice = function() { |
| + return Promise.reject(new DOMException( |
| + 'Bluetooth Low Energy is not supported on this platform.', |
| + 'NotFoundError')); |
| + }; |
| + } |
| + } |
| + |
| + navigator.bluetooth.test = new FakeBluetooth(); |
| +})(); |