Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: third_party/WebKit/LayoutTests/resources/web-bluetooth-test.js

Issue 2737343003: bluetooth: Add FakeBluetooth interface (Closed)
Patch Set: Add all the READMEs! Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 (() => {
2 let mojo_;
3
4 async function loadFakeBluetoothInterfaces() {
5 if(typeof mojo_ !== 'undefined') {
6 return mojo_;
7 }
8
9 if (typeof loadMojoModules === 'undefined') {
10 throw 'Mojo is required for this API.'
11 }
12
13 mojo_ = await loadMojoModules('fakeBluetooth', [
14 'mojo/public/js/bindings',
15 'device/bluetooth/public/interfaces/test/fake_bluetooth.mojom'
16 ]);
17
18 [mojo_.bindings, mojo_.FakeBluetooth] = mojo_.modules;
19 return mojo_;
20 }
21
22 class FakeBluetooth {
23 constructor() {
24 this.fake_bluetooth_ptr_ = undefined;
25 }
26
27 async setLEAvailability(available) {
28 if (typeof available !== 'boolean') throw 'Type Not Supported';
29 await (await this.getFakeBluetoothInterface_()).setLEAvailability(availabl e);
30
31 // TODO(crbug.com/569709): Remove once FakeBluetooth.setLEAvailability is
32 // implemented in the browser.
33 navigator.bluetooth.requestDevice = function() {
34 return Promise.reject(new DOMException(
35 'Bluetooth Low Energy is not supported on this platform.',
36 'NotFoundError'));
37 };
38 }
39
40 async getFakeBluetoothInterface_() {
41 if (typeof this.fake_bluetooth_ptr_ !== 'undefined') {
42 return this.fake_bluetooth_ptr_;
43 }
44
45 let mojo = await loadFakeBluetoothInterfaces();
46
47 this.fake_bluetooth_ptr_ = new mojo.FakeBluetooth.FakeBluetoothPtr(
48 mojo.interfaces.getInterface(
49 mojo.FakeBluetooth.FakeBluetooth.name));
50
51 return this.fake_bluetooth_ptr_;
52 }
53 }
54
55 navigator.bluetooth.test = new FakeBluetooth();
56 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698