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

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

Issue 2737343003: bluetooth: Add FakeBluetooth interface (Closed)
Patch Set: move web-bluetooth-test.js 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
« no previous file with comments | « third_party/WebKit/LayoutTests/bluetooth/requestDevice/le-not-supported.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Set it to indicate whether the platform supports BLE. For example,
28 // Windows 7 is a platform that doesn't support Low Energy. On the other
29 // hand Windows 10 is a platform that does support LE, even if there is no
30 // Bluetooth radio available.
31 async setLESupported(available) {
32 if (typeof available !== 'boolean') throw 'Type Not Supported';
33 await (await this.getFakeBluetoothInterface_()).setLESupported(available);
34
35 // TODO(crbug.com/569709): Remove once FakeBluetooth.setLESupported is
36 // implemented in the browser.
37 navigator.bluetooth.requestDevice = function() {
38 return Promise.reject(new DOMException(
39 'Bluetooth Low Energy is not supported on this platform.',
40 'NotFoundError'));
41 };
42 }
43
44 async getFakeBluetoothInterface_() {
45 if (typeof this.fake_bluetooth_ptr_ !== 'undefined') {
46 return this.fake_bluetooth_ptr_;
47 }
48
49 let mojo = await loadFakeBluetoothInterfaces();
50
51 this.fake_bluetooth_ptr_ = new mojo.FakeBluetooth.FakeBluetoothPtr(
52 mojo.interfaces.getInterface(
53 mojo.FakeBluetooth.FakeBluetooth.name));
54
55 return this.fake_bluetooth_ptr_;
56 }
57 }
58
59 navigator.bluetooth.test = new FakeBluetooth();
60 })();
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/bluetooth/requestDevice/le-not-supported.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698