Index: third_party/WebKit/LayoutTests/resources/bluetooth/bluetooth-helpers.js |
diff --git a/third_party/WebKit/LayoutTests/resources/bluetooth/bluetooth-helpers.js b/third_party/WebKit/LayoutTests/resources/bluetooth/bluetooth-helpers.js |
index fd9719a503127e16868524ab3d36bc68be4464de..bc1e607c11cdd06824070dc647ec4c606f08a13f 100644 |
--- a/third_party/WebKit/LayoutTests/resources/bluetooth/bluetooth-helpers.js |
+++ b/third_party/WebKit/LayoutTests/resources/bluetooth/bluetooth-helpers.js |
@@ -318,6 +318,22 @@ class EventCatcher { |
} |
} |
+// Returns a function that when called returns a promise that resolves when |
+// the device has disconnected. Example: |
+// device.gatt.connect() |
+// .then(gatt => get_request_disconnection(gatt)) |
+// .then(requestDisconnection => requestDisconnection()) |
+// .then(() => // device is now disconnected) |
+function get_request_disconnection(gattServer) { |
+ return gattServer.getPrimaryService(request_disconnection_service_uuid) |
+ .then(service => service.getCharacteristic(request_disconnection_characteristic_uuid)) |
+ .then(characteristic => { |
+ // TODO(crbug.com/543466): Wrap in assert_promise_rejects_with_message() |
+ // once connection is required for writeValue to succeed. |
+ return () => characteristic.writeValue(new Uint8Array([0])); |
+ }); |
+} |
+ |
function generateRequestDeviceArgsWithServices(services = ['heart_rate']) { |
return [{ |
filters: [{ services: services }] |