summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse')
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse/buffer-is-detached.https.window.js27
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse/characteristic-is-removed.https.window.js17
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse/gen-characteristic-is-removed.https.window.js22
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse/service-is-removed.https.window.js18
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse/write-succeeds.https.window.js47
5 files changed, 131 insertions, 0 deletions
diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse/buffer-is-detached.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse/buffer-is-detached.https.window.js
new file mode 100644
index 0000000000..ebd8aefeca
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse/buffer-is-detached.https.window.js
@@ -0,0 +1,27 @@
+// META: script=/resources/testdriver.js
+// META: script=/resources/testdriver-vendor.js
+// META: script=/bluetooth/resources/bluetooth-test.js
+// META: script=/bluetooth/resources/bluetooth-fake-devices.js
+'use strict';
+const test_desc =
+ 'writeValueWithResponse() fails when passed a detached buffer';
+
+function detachBuffer(buffer) {
+ window.postMessage('', '*', [buffer]);
+}
+
+bluetooth_test(async (t) => {
+ const {characteristic} = await getMeasurementIntervalCharacteristic();
+
+ const typed_array = Uint8Array.of(1, 2);
+ detachBuffer(typed_array.buffer);
+ await promise_rejects_dom(
+ t, 'InvalidStateError',
+ characteristic.writeValueWithResponse(typed_array));
+
+ const array_buffer = Uint8Array.of(3, 4).buffer;
+ detachBuffer(array_buffer);
+ await promise_rejects_dom(
+ t, 'InvalidStateError',
+ characteristic.writeValueWithResponse(array_buffer));
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse/characteristic-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse/characteristic-is-removed.https.window.js
new file mode 100644
index 0000000000..9309cd5a3c
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse/characteristic-is-removed.https.window.js
@@ -0,0 +1,17 @@
+// META: script=/resources/testdriver.js
+// META: script=/resources/testdriver-vendor.js
+// META: script=/bluetooth/resources/bluetooth-test.js
+// META: script=/bluetooth/resources/bluetooth-fake-devices.js
+'use strict';
+const test_desc = 'Characteristic gets removed. Reject with InvalidStateError.';
+const expected = new DOMException(
+ 'GATT Characteristic no longer exists.', 'InvalidStateError');
+
+bluetooth_test(async () => {
+ const {characteristic, fake_characteristic} =
+ await getMeasurementIntervalCharacteristic();
+ await fake_characteristic.remove();
+ await assert_promise_rejects_with_message(
+ characteristic.writeValueWithResponse(new ArrayBuffer(1 /* length */)),
+ expected, 'Characteristic got removed.');
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse/gen-characteristic-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse/gen-characteristic-is-removed.https.window.js
new file mode 100644
index 0000000000..e202376da7
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse/gen-characteristic-is-removed.https.window.js
@@ -0,0 +1,22 @@
+// META: script=/resources/testdriver.js
+// META: script=/resources/testdriver-vendor.js
+// META: script=/common/gc.js
+// META: script=/bluetooth/resources/bluetooth-test.js
+// META: script=/bluetooth/resources/bluetooth-fake-devices.js
+// Generated by //third_party/WebKit/LayoutTests/bluetooth/generate.py
+'use strict';
+const test_desc = 'Characteristic gets removed. Reject with InvalidStateError.';
+const expected = new DOMException('GATT Characteristic no longer exists.',
+ 'InvalidStateError');
+let fake_peripheral, characteristic, fake_characteristic;
+
+bluetooth_test(() => getMeasurementIntervalCharacteristic()
+ .then(_ => ({fake_peripheral, characteristic, fake_characteristic} = _))
+ .then(() => characteristic.getDescriptor(user_description.name))
+ .then(() => null, (e) => assert_unreached('Caught error unexpectedly.', e))
+ .then(() => fake_characteristic.remove())
+ .then(() => fake_peripheral.simulateGATTServicesChanged())
+ .then(() => assert_promise_rejects_with_message(
+ characteristic.writeValueWithResponse(new Uint8Array(1)), expected)),
+ test_desc);
+
diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse/service-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse/service-is-removed.https.window.js
new file mode 100644
index 0000000000..81b2dff44e
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse/service-is-removed.https.window.js
@@ -0,0 +1,18 @@
+// META: script=/resources/testdriver.js
+// META: script=/resources/testdriver-vendor.js
+// META: script=/bluetooth/resources/bluetooth-test.js
+// META: script=/bluetooth/resources/bluetooth-fake-devices.js
+'use strict';
+const test_desc = 'Service gets removed. Reject with InvalidStateError.';
+const expected =
+ new DOMException('GATT Service no longer exists.', 'InvalidStateError');
+
+bluetooth_test(async () => {
+ const {characteristic, fake_peripheral, fake_service} =
+ await getMeasurementIntervalCharacteristic();
+ await fake_service.remove();
+ await fake_peripheral.simulateGATTServicesChanged();
+ await assert_promise_rejects_with_message(
+ characteristic.writeValueWithResponse(new ArrayBuffer(1 /* length */)),
+ expected, 'Service got removed.');
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse/write-succeeds.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse/write-succeeds.https.window.js
new file mode 100644
index 0000000000..c87e7ac6ab
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithResponse/write-succeeds.https.window.js
@@ -0,0 +1,47 @@
+// META: script=/resources/testdriver.js
+// META: script=/resources/testdriver-vendor.js
+// META: script=/bluetooth/resources/bluetooth-test.js
+// META: script=/bluetooth/resources/bluetooth-fake-devices.js
+'use strict';
+const test_desc = 'A regular write request to a writable characteristic ' +
+ 'should succeed.';
+
+bluetooth_test(async () => {
+ const {characteristic, fake_characteristic} =
+ await getMeasurementIntervalCharacteristic();
+
+ let lastValue, lastWriteType;
+ ({lastValue, lastWriteType} =
+ await fake_characteristic.getLastWrittenValue());
+ assert_equals(lastValue, null);
+ assert_equals(lastWriteType, 'none');
+
+ await fake_characteristic.setNextWriteResponse(GATT_SUCCESS);
+
+ const typed_array = Uint8Array.of(1, 2);
+ await characteristic.writeValueWithResponse(typed_array);
+ ({lastValue, lastWriteType} =
+ await fake_characteristic.getLastWrittenValue());
+ assert_array_equals(lastValue, [1, 2]);
+ assert_equals(lastWriteType, 'with-response');
+
+ await fake_characteristic.setNextWriteResponse(GATT_SUCCESS);
+
+ const array_buffer = Uint8Array.of(3, 4).buffer;
+ await characteristic.writeValueWithResponse(array_buffer);
+ ({lastValue, lastWriteType} =
+ await fake_characteristic.getLastWrittenValue());
+ assert_array_equals(lastValue, [3, 4]);
+ assert_equals(lastWriteType, 'with-response');
+
+ await fake_characteristic.setNextWriteResponse(GATT_SUCCESS);
+
+ const data_view = new DataView(new ArrayBuffer(2));
+ data_view.setUint8(0, 5);
+ data_view.setUint8(1, 6);
+ await characteristic.writeValueWithResponse(data_view);
+ ({lastValue, lastWriteType} =
+ await fake_characteristic.getLastWrittenValue());
+ assert_array_equals(lastValue, [5, 6]);
+ assert_equals(lastWriteType, 'with-response');
+}, test_desc);