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..dfd8f2c24bf08c3d401eff2b0fd7fdb5b998469f |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/resources/web-bluetooth-test.js |
@@ -0,0 +1,56 @@ |
+(() => { |
+ 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; |
+ } |
+ |
+ async setLEAvailability(available) { |
+ if (typeof available !== 'boolean') throw 'Type Not Supported'; |
+ await (await this.getFakeBluetoothInterface_()).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')); |
+ }; |
+ } |
+ |
+ 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(); |
+})(); |