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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
new file mode 100644
index 0000000000000000000000000000000000000000..d391827f227e120cff52f08b585481fc11e3d79f
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/resources/bluetooth/web-bluetooth-test.js
@@ -0,0 +1,60 @@
+(() => {
+ let mojo_;
+
+ async function loadFakeBluetoothInterfaces() {
+ if(typeof mojo_ !== 'undefined') {
+ return mojo_;
+ }
+
+ if (typeof loadMojoModules === 'undefined') {
+ throw 'Mojo is required for this API.'
+ }
+
+ mojo_ = await loadMojoModules('fakeBluetooth', [
+ 'mojo/public/js/bindings',
+ 'device/bluetooth/public/interfaces/test/fake_bluetooth.mojom'
+ ]);
+
+ [mojo_.bindings, mojo_.FakeBluetooth] = mojo_.modules;
+ return mojo_;
+ }
+
+ class FakeBluetooth {
+ constructor() {
+ this.fake_bluetooth_ptr_ = undefined;
+ }
+
+ // Set it to indicate whether the platform supports BLE. For example,
+ // Windows 7 is a platform that doesn't support Low Energy. On the other
+ // hand Windows 10 is a platform that does support LE, even if there is no
+ // Bluetooth radio available.
+ async setLESupported(available) {
+ if (typeof available !== 'boolean') throw 'Type Not Supported';
+ await (await this.getFakeBluetoothInterface_()).setLESupported(available);
+
+ // TODO(crbug.com/569709): Remove once FakeBluetooth.setLESupported is
+ // implemented in the browser.
+ navigator.bluetooth.requestDevice = function() {
+ return Promise.reject(new DOMException(
+ 'Bluetooth Low Energy is not supported on this platform.',
+ 'NotFoundError'));
+ };
+ }
+
+ async getFakeBluetoothInterface_() {
+ if (typeof this.fake_bluetooth_ptr_ !== 'undefined') {
+ return this.fake_bluetooth_ptr_;
+ }
+
+ let mojo = await loadFakeBluetoothInterfaces();
+
+ this.fake_bluetooth_ptr_ = new mojo.FakeBluetooth.FakeBluetoothPtr(
+ mojo.interfaces.getInterface(
+ mojo.FakeBluetooth.FakeBluetooth.name));
+
+ return this.fake_bluetooth_ptr_;
+ }
+ }
+
+ navigator.bluetooth.test = new FakeBluetooth();
+})();
« 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