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

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

Issue 2853433002: bluetooth: Implement simulateCentral (Closed)
Patch Set: Address dcheng's comments 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/radio-off.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
index eee28a3e18d1cc4748815f38276b702f755942a7..7cf767f905a944bccf6d7cbf305fab0004d65d97 100644
--- a/third_party/WebKit/LayoutTests/resources/bluetooth/web-bluetooth-test.js
+++ b/third_party/WebKit/LayoutTests/resources/bluetooth/web-bluetooth-test.js
@@ -15,7 +15,14 @@
'device/bluetooth/public/interfaces/test/fake_bluetooth.mojom'
]);
- [mojo_.bindings, mojo_.FakeBluetooth] = mojo_.modules;
+ [mojo_.bindings, {
+ CentralState: mojo_.CentralState,
+ FakeBluetooth: mojo_.FakeBluetooth,
+ FakeBluetoothPtr: mojo_.FakeBluetoothPtr,
+ FakeCentral: mojo_.FakeCentral,
+ FakeCentralPtr: mojo_.FakeCentralPtr,
+ }] = mojo_.modules;
+
return mojo_;
}
@@ -33,6 +40,53 @@
await (await this.getFakeBluetoothInterface_()).setLESupported(available);
}
+ // Returns a promise that resolves with a FakeCentral that clients can use
+ // to simulate events that a device in the Central/Observer role would
+ // receive as well as monitor the operations performed by the device in the
+ // Central/Observer role.
+ // Calls sets LE as supported.
+ //
+ // A "Central" object would allow its clients to receive advertising events
+ // and initiate connections to peripherals i.e. operations of two roles
+ // defined by the Bluetooth Spec: Observer and Central.
+ // See Bluetooth 4.2 Vol 3 Part C 2.2.2 "Roles when Operating over an
+ // LE Physical Transport".
+ async simulateCentral({state}) {
+ // Call setBluetoothFakeAdapter() to clean up any fake adapters left over
+ // by legacy tests.
+ // Legacy tests that use setBluetoothFakeAdapter() sometimes fail to clean
+ // their fake adapter. This is not a problem for these tests because the
+ // next setBluetoothFakeAdapter() will clean it up anyway but it is a
+ // problem for the new tests that do not use setBluetoothFakeAdapter().
+ // TODO(crbug.com/569709): Remove once setBluetoothFakeAdapter is no
+ // longer used.
+ await setBluetoothFakeAdapter('');
+
+ await this.setLESupported(true);
+ let mojo = await loadFakeBluetoothInterfaces();
+
+ let mojo_manager_state;
+ switch (state) {
+ case 'absent':
+ mojo_manager_state = mojo.CentralState.ABSENT;
+ break;
+ case 'powered-off':
+ mojo_manager_state = mojo.CentralState.POWERED_OFF;
+ break;
+ case 'powered-on':
+ mojo_manager_state = mojo.CentralState.POWERED_ON;
+ break;
+ default:
+ throw `Unsupported value ${state} for state.`;
+ }
+
+ let {fake_central:fake_central_ptr} =
+ await (await this.getFakeBluetoothInterface_()).simulateCentral(
+ mojo_manager_state);
+
+ return new FakeCentral(fake_central_ptr);
+ }
+
async getFakeBluetoothInterface_() {
if (typeof this.fake_bluetooth_ptr_ !== 'undefined') {
return this.fake_bluetooth_ptr_;
@@ -40,13 +94,21 @@
let mojo = await loadFakeBluetoothInterfaces();
- this.fake_bluetooth_ptr_ = new mojo.FakeBluetooth.FakeBluetoothPtr(
- mojo.interfaces.getInterface(
- mojo.FakeBluetooth.FakeBluetooth.name));
+ this.fake_bluetooth_ptr_ = new mojo.FakeBluetoothPtr(
+ mojo.interfaces.getInterface(mojo.FakeBluetooth.name));
return this.fake_bluetooth_ptr_;
}
}
+ // FakeCentral allows clients to simulate events that a device in the
+ // Central/Observer role would receive as well as monitor the operations
+ // performed by the device in the Central/Observer role.
+ class FakeCentral {
+ constructor(fake_central_ptr) {
+ this.fake_central_ptr = fake_central_ptr;
+ }
+ }
+
navigator.bluetooth.test = new FakeBluetooth();
})();
« no previous file with comments | « third_party/WebKit/LayoutTests/bluetooth/requestDevice/radio-off.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698