summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/bluetooth/characteristic/readValue
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/bluetooth/characteristic/readValue')
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/readValue/add-multiple-event-listeners.https.window.js25
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/readValue/characteristic-is-removed.https.window.js16
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/readValue/detachedIframe.https.window.js33
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/readValue/event-is-fired.https.window.js23
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/readValue/gen-characteristic-is-removed.https.window.js22
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/readValue/read-succeeds.https.window.js16
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/readValue/read-updates-value.https.window.js17
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/readValue/service-is-removed.https.window.js17
8 files changed, 169 insertions, 0 deletions
diff --git a/testing/web-platform/tests/bluetooth/characteristic/readValue/add-multiple-event-listeners.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/readValue/add-multiple-event-listeners.https.window.js
new file mode 100644
index 0000000000..0eeafd0b79
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/readValue/add-multiple-event-listeners.https.window.js
@@ -0,0 +1,25 @@
+// 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 = 'Add multiple event listeners then readValue().';
+
+bluetooth_test(async () => {
+ const {characteristic, fake_characteristic} =
+ await getMeasurementIntervalCharacteristic();
+ await fake_characteristic.setNextReadResponse(GATT_SUCCESS, [0, 1, 2]);
+
+ // Make sure that |characteristic.readValue()| resolves after
+ // |characteristicvaluechanged| is fired |3| times.
+ const results = await assert_promise_resolves_after_event(
+ characteristic /* object */, 'readValue' /* func */,
+ 'characteristicvaluechanged' /* event */, 3 /* num_listeners */);
+
+ const read_value = new Uint8Array(results[0].buffer);
+ const event_values = results.slice(1).map(v => new Uint8Array(v.buffer));
+ for (const event_value of event_values) {
+ assert_equals(event_value.buffer, read_value.buffer);
+ assert_array_equals(event_value, read_value);
+ }
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/characteristic/readValue/characteristic-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/readValue/characteristic-is-removed.https.window.js
new file mode 100644
index 0000000000..e97b94f736
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/readValue/characteristic-is-removed.https.window.js
@@ -0,0 +1,16 @@
+// 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.readValue(), expected, 'Characteristic got removed.');
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/characteristic/readValue/detachedIframe.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/readValue/detachedIframe.https.window.js
new file mode 100644
index 0000000000..6e2510b58d
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/readValue/detachedIframe.https.window.js
@@ -0,0 +1,33 @@
+// 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
+
+bluetooth_test(async () => {
+ let iframe = document.createElement('iframe');
+ let error;
+
+ const {device, fakes} = await getHealthThermometerDeviceFromIframe(iframe);
+ await fakes.fake_peripheral.setNextGATTDiscoveryResponse({
+ code: HCI_SUCCESS,
+ });
+ let service = await device.gatt.getPrimaryService(health_thermometer.name);
+ let characteristic =
+ await service.getCharacteristic(measurement_interval.name);
+
+ iframe.remove();
+ // Set iframe to null to ensure that the GC cleans up as much as possible.
+ iframe = null;
+ await garbageCollect();
+
+ try {
+ await characteristic.readValue();
+ } catch (e) {
+ // Cannot use promise_rejects_dom() because |e| is thrown from a different
+ // global.
+ error = e;
+ }
+ assert_not_equals(error, undefined);
+ assert_equals(error.name, 'NetworkError');
+}, 'readValue() rejects in a detached context');
diff --git a/testing/web-platform/tests/bluetooth/characteristic/readValue/event-is-fired.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/readValue/event-is-fired.https.window.js
new file mode 100644
index 0000000000..52b70e7a08
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/readValue/event-is-fired.https.window.js
@@ -0,0 +1,23 @@
+// 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 = 'Reading a characteristic should fire an event.';
+
+bluetooth_test(async () => {
+ const {characteristic, fake_characteristic} =
+ await getMeasurementIntervalCharacteristic();
+ await fake_characteristic.setNextReadResponse(GATT_SUCCESS, [0, 1, 2]);
+
+ // Make sure that |characteristic.readValue()| resolves after
+ // |characteristicvaluechanged| is fired.
+ const results = await assert_promise_resolves_after_event(
+ characteristic /* object */, 'readValue' /* func */,
+ 'characteristicvaluechanged' /* event */);
+
+ const read_value = new Uint8Array(results[0].buffer);
+ const event_value = new Uint8Array(results[1].buffer);
+ assert_equals(event_value.buffer, read_value.buffer);
+ assert_array_equals(event_value, read_value);
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/characteristic/readValue/gen-characteristic-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/readValue/gen-characteristic-is-removed.https.window.js
new file mode 100644
index 0000000000..5bee6db107
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/readValue/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.readValue(), expected)),
+ test_desc);
+
diff --git a/testing/web-platform/tests/bluetooth/characteristic/readValue/read-succeeds.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/readValue/read-succeeds.https.window.js
new file mode 100644
index 0000000000..e5ddfb8169
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/readValue/read-succeeds.https.window.js
@@ -0,0 +1,16 @@
+// 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 read request succeeds and returns the characteristic\'s ' +
+ 'value.';
+const EXPECTED_VALUE = [0, 1, 2];
+
+bluetooth_test(async () => {
+ const {characteristic, fake_characteristic} =
+ await getMeasurementIntervalCharacteristic();
+ await fake_characteristic.setNextReadResponse(GATT_SUCCESS, EXPECTED_VALUE);
+ const value = await characteristic.readValue();
+ assert_array_equals(new Uint8Array(value.buffer), EXPECTED_VALUE)
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/characteristic/readValue/read-updates-value.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/readValue/read-updates-value.https.window.js
new file mode 100644
index 0000000000..bb98aeb18f
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/readValue/read-updates-value.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
+const test_desc = 'Succesful read should update characteristic.value';
+const EXPECTED_VALUE = [0, 1, 2];
+
+bluetooth_test(async () => {
+ const {characteristic, fake_characteristic} =
+ await getMeasurementIntervalCharacteristic();
+ assert_equals(characteristic.value, null);
+
+ await fake_characteristic.setNextReadResponse(GATT_SUCCESS, EXPECTED_VALUE);
+ await characteristic.readValue();
+ assert_array_equals(
+ new Uint8Array(characteristic.value.buffer), EXPECTED_VALUE)
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/characteristic/readValue/service-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/readValue/service-is-removed.https.window.js
new file mode 100644
index 0000000000..1f699ca25e
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/readValue/service-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 = '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.readValue(), expected, 'Service got removed.')
+}, test_desc);