diff --git a/bluetooth/resources/bluetooth-helpers.js b/bluetooth/resources/bluetooth-helpers.js index 56357043ba7b06..2fc8a315fba407 100644 --- a/bluetooth/resources/bluetooth-helpers.js +++ b/bluetooth/resources/bluetooth-helpers.js @@ -43,6 +43,7 @@ function performChromiumSetup() { `${prefix}/uuid.mojom.js`, `${prefix}/fake_bluetooth.mojom.js`, `${prefix}/web-bluetooth-test.js`, + 'file:///gen/content/shell/common/layout_test/fake_bluetooth_chooser.mojom.js', ].concat(extra)) // Call setBluetoothFakeAdapter() to clean up any fake adapters left over // by legacy tests. diff --git a/resources/chromium/web-bluetooth-test.js b/resources/chromium/web-bluetooth-test.js index 42656d3f756061..c10685f376c730 100644 --- a/resources/chromium/web-bluetooth-test.js +++ b/resources/chromium/web-bluetooth-test.js @@ -65,7 +65,7 @@ class FakeBluetooth { constructor() { this.fake_bluetooth_ptr_ = new bluetooth.mojom.FakeBluetoothPtr(); Mojo.bindInterface(bluetooth.mojom.FakeBluetooth.name, - mojo.makeRequest(this.fake_bluetooth_ptr_).handle, "process"); + mojo.makeRequest(this.fake_bluetooth_ptr_).handle, 'process'); } // Set it to indicate whether the platform supports BLE. For example, @@ -102,6 +102,15 @@ class FakeBluetooth { let {consumed} = await this.fake_bluetooth_ptr_.allResponsesConsumed(); return consumed; } + + // Returns a promise that resolves with a FakeChooser that clients can use to + // simulate chooser events. + async getManualChooser() { + if (typeof this.fake_chooser_ === 'undefined') { + this.fake_chooser_ = new FakeChooser(); + } + return this.fake_chooser_; + } } // FakeCentral allows clients to simulate events that a device in the @@ -437,6 +446,17 @@ class FakeRemoteGATTDescriptor { } } +// FakeChooser allows clients to simulate events that a user would trigger when +// using the Bluetooth chooser, and monitor the events that are produced. +class FakeChooser { + constructor() { + this.fake_bluetooth_chooser_ptr_ = + new content.mojom.FakeBluetoothChooserPtr(); + Mojo.bindInterface(content.mojom.FakeBluetoothChooser.name, + mojo.makeRequest(this.fake_bluetooth_chooser_ptr_).handle, 'process'); + } +} + // If this line fails, it means that current environment does not support the // Web Bluetooth Test API. try {