summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/bluetooth/characteristic
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/bluetooth/characteristic')
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/characteristicProperties.https.window.js22
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/getDescriptor/detachedIframe.https.window.js33
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/getDescriptor/gen-characteristic-is-removed.https.window.js22
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/getDescriptor/gen-descriptor-get-same-object.https.window.js36
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/getDescriptor/gen-service-is-removed.https.window.js24
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/getDescriptors/detachedIframe.https.window.js33
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/getDescriptors/gen-characteristic-is-removed-with-uuid.https.window.js22
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/getDescriptors/gen-characteristic-is-removed.https.window.js22
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/getDescriptors/gen-descriptor-get-same-object.https.window.js36
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/getDescriptors/gen-service-is-removed-with-uuid.https.window.js24
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/getDescriptors/gen-service-is-removed.https.window.js24
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/notifications/characteristic-is-removed.https.window.js17
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/notifications/service-is-removed.https.window.js17
-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.js21
-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
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/service-same-from-2-characteristics.https.window.js15
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/service-same-object.https.window.js12
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/startNotifications/detachedIframe.https.window.js33
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/startNotifications/gen-characteristic-is-removed.https.window.js22
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/stopNotifications/detachedIframe.https.window.js33
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/writeValue/buffer-is-detached.https.window.js24
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/writeValue/characteristic-is-removed.https.window.js17
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/writeValue/detachedIframe.https.window.js33
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/writeValue/gen-characteristic-is-removed.https.window.js22
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/writeValue/service-is-removed.https.window.js18
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/writeValue/write-succeeds.https.window.js47
-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
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/buffer-is-detached.https.window.js27
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/characteristic-is-removed.https.window.js17
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/gen-characteristic-is-removed.https.window.js22
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/service-is-removed.https.window.js18
-rw-r--r--testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/write-succeeds.https.window.js41
42 files changed, 1038 insertions, 0 deletions
diff --git a/testing/web-platform/tests/bluetooth/characteristic/characteristicProperties.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/characteristicProperties.https.window.js
new file mode 100644
index 0000000000..f7a57a9c4b
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/characteristicProperties.https.window.js
@@ -0,0 +1,22 @@
+// 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 = 'HeartRate device properties';
+
+bluetooth_test(async () => {
+ const {service} = await getHealthThermometerService()
+ const [temperature_measurement, measurement_interval] = await Promise.all([
+ service.getCharacteristic('temperature_measurement'),
+ service.getCharacteristic('measurement_interval')
+ ]);
+ const tm_expected_properties = new TestCharacteristicProperties(['indicate']);
+ assert_properties_equal(
+ temperature_measurement.properties, tm_expected_properties);
+
+ const mi_expected_properties =
+ new TestCharacteristicProperties(['read', 'write', 'indicate']);
+ assert_properties_equal(
+ measurement_interval.properties, mi_expected_properties);
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/characteristic/getDescriptor/detachedIframe.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/getDescriptor/detachedIframe.https.window.js
new file mode 100644
index 0000000000..de7d0b0b7c
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/getDescriptor/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.getDescriptor(user_description.name);
+ } 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');
+}, 'getDescriptor() rejects in a detached context');
diff --git a/testing/web-platform/tests/bluetooth/characteristic/getDescriptor/gen-characteristic-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/getDescriptor/gen-characteristic-is-removed.https.window.js
new file mode 100644
index 0000000000..9e48a7caab
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/getDescriptor/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.getDescriptor(user_description.name), expected)),
+ test_desc);
+
diff --git a/testing/web-platform/tests/bluetooth/characteristic/getDescriptor/gen-descriptor-get-same-object.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/getDescriptor/gen-descriptor-get-same-object.https.window.js
new file mode 100644
index 0000000000..708f67da6a
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/getDescriptor/gen-descriptor-get-same-object.https.window.js
@@ -0,0 +1,36 @@
+// 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 = 'Calls to getDescriptor should return the same object.';
+let characteristic;
+
+bluetooth_test(() => getMeasurementIntervalCharacteristic()
+ .then(_ => ({characteristic} = _))
+ .then(() => Promise.all([
+ characteristic.getDescriptor(user_description.alias),
+ characteristic.getDescriptor(user_description.name),
+ characteristic.getDescriptor(user_description.uuid)
+ ]))
+ .then(descriptors_arrays => {
+ assert_true(descriptors_arrays.length > 0)
+
+ // Convert to arrays if necessary.
+ for (let i = 0; i < descriptors_arrays.length; i++) {
+ descriptors_arrays[i] = [].concat(descriptors_arrays[i]);
+ }
+
+ for (let i = 1; i < descriptors_arrays.length; i++) {
+ assert_equals(descriptors_arrays[0].length,
+ descriptors_arrays[i].length);
+ }
+
+ let base_set = new Set(descriptors_arrays[0]);
+ for (let descriptors of descriptors_arrays) {
+ descriptors.forEach(descriptor => assert_true(base_set.has(descriptor)));
+ }
+ }), test_desc);
+
diff --git a/testing/web-platform/tests/bluetooth/characteristic/getDescriptor/gen-service-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/getDescriptor/gen-service-is-removed.https.window.js
new file mode 100644
index 0000000000..c256050b0f
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/getDescriptor/gen-service-is-removed.https.window.js
@@ -0,0 +1,24 @@
+// 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
+// TODO(https://crbug.com/672127) Use this test case to test the rest of
+// characteristic functions.
+'use strict';
+const test_desc = 'Service is removed. Reject with InvalidStateError.';
+const expected = new DOMException('GATT Service no longer exists.',
+ 'InvalidStateError');
+let characteristic, fake_peripheral, fake_service;
+
+bluetooth_test(() => getMeasurementIntervalCharacteristic()
+ .then(_ => ({characteristic, fake_peripheral, fake_service} = _))
+ .then(() => fake_service.remove())
+ .then(() => fake_peripheral.simulateGATTServicesChanged())
+ .then(() => assert_promise_rejects_with_message(
+ characteristic.getDescriptor(user_description.name),
+ expected,
+ 'Service got removed.')),
+ test_desc);
+
diff --git a/testing/web-platform/tests/bluetooth/characteristic/getDescriptors/detachedIframe.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/getDescriptors/detachedIframe.https.window.js
new file mode 100644
index 0000000000..45dd23752f
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/getDescriptors/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.getDescriptors(user_description.name);
+ } 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');
+}, 'getDescriptors() rejects in a detached context');
diff --git a/testing/web-platform/tests/bluetooth/characteristic/getDescriptors/gen-characteristic-is-removed-with-uuid.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/getDescriptors/gen-characteristic-is-removed-with-uuid.https.window.js
new file mode 100644
index 0000000000..a0424c0110
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/getDescriptors/gen-characteristic-is-removed-with-uuid.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.getDescriptors(user_description.name), expected)),
+ test_desc);
+
diff --git a/testing/web-platform/tests/bluetooth/characteristic/getDescriptors/gen-characteristic-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/getDescriptors/gen-characteristic-is-removed.https.window.js
new file mode 100644
index 0000000000..29325c3bb5
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/getDescriptors/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.getDescriptors(), expected)),
+ test_desc);
+
diff --git a/testing/web-platform/tests/bluetooth/characteristic/getDescriptors/gen-descriptor-get-same-object.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/getDescriptors/gen-descriptor-get-same-object.https.window.js
new file mode 100644
index 0000000000..7f1001f3ee
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/getDescriptors/gen-descriptor-get-same-object.https.window.js
@@ -0,0 +1,36 @@
+// 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 = 'Calls to getDescriptors should return the same object.';
+let characteristic;
+
+bluetooth_test(() => getMeasurementIntervalCharacteristic()
+ .then(_ => ({characteristic} = _))
+ .then(() => Promise.all([
+ characteristic.getDescriptors(user_description.alias),
+ characteristic.getDescriptors(user_description.name),
+ characteristic.getDescriptors(user_description.uuid)
+ ]))
+ .then(descriptors_arrays => {
+ assert_true(descriptors_arrays.length > 0)
+
+ // Convert to arrays if necessary.
+ for (let i = 0; i < descriptors_arrays.length; i++) {
+ descriptors_arrays[i] = [].concat(descriptors_arrays[i]);
+ }
+
+ for (let i = 1; i < descriptors_arrays.length; i++) {
+ assert_equals(descriptors_arrays[0].length,
+ descriptors_arrays[i].length);
+ }
+
+ let base_set = new Set(descriptors_arrays[0]);
+ for (let descriptors of descriptors_arrays) {
+ descriptors.forEach(descriptor => assert_true(base_set.has(descriptor)));
+ }
+ }), test_desc);
+
diff --git a/testing/web-platform/tests/bluetooth/characteristic/getDescriptors/gen-service-is-removed-with-uuid.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/getDescriptors/gen-service-is-removed-with-uuid.https.window.js
new file mode 100644
index 0000000000..b7c4bff32d
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/getDescriptors/gen-service-is-removed-with-uuid.https.window.js
@@ -0,0 +1,24 @@
+// 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
+// TODO(https://crbug.com/672127) Use this test case to test the rest of
+// characteristic functions.
+'use strict';
+const test_desc = 'Service is removed. Reject with InvalidStateError.';
+const expected = new DOMException('GATT Service no longer exists.',
+ 'InvalidStateError');
+let characteristic, fake_peripheral, fake_service;
+
+bluetooth_test(() => getMeasurementIntervalCharacteristic()
+ .then(_ => ({characteristic, fake_peripheral, fake_service} = _))
+ .then(() => fake_service.remove())
+ .then(() => fake_peripheral.simulateGATTServicesChanged())
+ .then(() => assert_promise_rejects_with_message(
+ characteristic.getDescriptors(user_description.uuid),
+ expected,
+ 'Service got removed.')),
+ test_desc);
+
diff --git a/testing/web-platform/tests/bluetooth/characteristic/getDescriptors/gen-service-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/getDescriptors/gen-service-is-removed.https.window.js
new file mode 100644
index 0000000000..22dc30f6d8
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/getDescriptors/gen-service-is-removed.https.window.js
@@ -0,0 +1,24 @@
+// 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
+// TODO(https://crbug.com/672127) Use this test case to test the rest of
+// characteristic functions.
+'use strict';
+const test_desc = 'Service is removed. Reject with InvalidStateError.';
+const expected = new DOMException('GATT Service no longer exists.',
+ 'InvalidStateError');
+let characteristic, fake_peripheral, fake_service;
+
+bluetooth_test(() => getMeasurementIntervalCharacteristic()
+ .then(_ => ({characteristic, fake_peripheral, fake_service} = _))
+ .then(() => fake_service.remove())
+ .then(() => fake_peripheral.simulateGATTServicesChanged())
+ .then(() => assert_promise_rejects_with_message(
+ characteristic.getDescriptors(user_description.name),
+ expected,
+ 'Service got removed.')),
+ test_desc);
+
diff --git a/testing/web-platform/tests/bluetooth/characteristic/notifications/characteristic-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/notifications/characteristic-is-removed.https.window.js
new file mode 100644
index 0000000000..9641ad71e9
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/notifications/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 is 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.startNotifications(), expected,
+ 'Characteristic got removed.');
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/characteristic/notifications/service-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/notifications/service-is-removed.https.window.js
new file mode 100644
index 0000000000..a5851fc473
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/notifications/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 is 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.startNotifications(), expected, 'Service got removed.');
+}, test_desc);
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..e80be43135
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/readValue/characteristic-is-removed.https.window.js
@@ -0,0 +1,21 @@
+// 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
+// META: timeout=long
+'use strict';
+const test_desc = 'Characteristic gets removed. Reject with InvalidStateError.';
+const expected = new DOMException(
+ 'GATT Characteristic no longer exists.', 'InvalidStateError');
+
+bluetooth_test_crbug1430625(async () => {
+ console.log('[crbug.com/1430625] To getMeasurementIntervalCharacteristic');
+ const {characteristic, fake_characteristic} =
+ await getMeasurementIntervalCharacteristic();
+ console.log('[crbug.com/1430625] To fake_characteristic.remove()');
+ await fake_characteristic.remove();
+ console.log('[crbug.com/1430625] To characteristic.readValue()');
+ await assert_promise_rejects_with_message(
+ characteristic.readValue(), expected, 'Characteristic got removed.');
+ console.log('[crbug.com/1430625] End of the test');
+}, 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);
diff --git a/testing/web-platform/tests/bluetooth/characteristic/service-same-from-2-characteristics.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/service-same-from-2-characteristics.https.window.js
new file mode 100644
index 0000000000..dafd755fd1
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/service-same-from-2-characteristics.https.window.js
@@ -0,0 +1,15 @@
+// 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 = 'Same parent service returned from multiple characteristics.';
+
+bluetooth_test(async () => {
+ const {service} = await getHealthThermometerService();
+ const characteristics = await Promise.all([
+ service.getCharacteristic('measurement_interval'),
+ service.getCharacteristic('temperature_measurement')
+ ]);
+ assert_equals(characteristics[0].service, characteristics[1].service);
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/characteristic/service-same-object.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/service-same-object.https.window.js
new file mode 100644
index 0000000000..01b3a25e35
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/service-same-object.https.window.js
@@ -0,0 +1,12 @@
+// 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 = '[SameObject] test for BluetoothRemoteGATTCharacteristic ' +
+ 'service.';
+
+bluetooth_test(async () => {
+ const {characteristic} = await getMeasurementIntervalCharacteristic();
+ assert_equals(characteristic.service, characteristic.service);
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/characteristic/startNotifications/detachedIframe.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/startNotifications/detachedIframe.https.window.js
new file mode 100644
index 0000000000..f09c52d328
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/startNotifications/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.startNotifications();
+ } 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');
+}, 'startNotifications() rejects in a detached context');
diff --git a/testing/web-platform/tests/bluetooth/characteristic/startNotifications/gen-characteristic-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/startNotifications/gen-characteristic-is-removed.https.window.js
new file mode 100644
index 0000000000..c2a23d7f44
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/startNotifications/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.startNotifications(), expected)),
+ test_desc);
+
diff --git a/testing/web-platform/tests/bluetooth/characteristic/stopNotifications/detachedIframe.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/stopNotifications/detachedIframe.https.window.js
new file mode 100644
index 0000000000..a459a5b15d
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/stopNotifications/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.stopNotifications();
+ } 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');
+}, 'stopNotifications() rejects in a detached context');
diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValue/buffer-is-detached.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValue/buffer-is-detached.https.window.js
new file mode 100644
index 0000000000..5d707775e1
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/writeValue/buffer-is-detached.https.window.js
@@ -0,0 +1,24 @@
+// 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 = 'writeValue() 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.writeValue(typed_array));
+
+ const array_buffer = Uint8Array.of(3, 4).buffer;
+ detachBuffer(array_buffer);
+ await promise_rejects_dom(
+ t, 'InvalidStateError', characteristic.writeValue(array_buffer));
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValue/characteristic-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValue/characteristic-is-removed.https.window.js
new file mode 100644
index 0000000000..6e9da8802c
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/writeValue/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.writeValue(new ArrayBuffer(1 /* length */)), expected,
+ 'Characteristic got removed.');
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValue/detachedIframe.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValue/detachedIframe.https.window.js
new file mode 100644
index 0000000000..eb243a3508
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/writeValue/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.writeValue(new DataView(new ArrayBuffer(2)));
+ } 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');
+}, 'writeValue() rejects in a detached context');
diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValue/gen-characteristic-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValue/gen-characteristic-is-removed.https.window.js
new file mode 100644
index 0000000000..5750cb82c7
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/writeValue/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.writeValue(new Uint8Array(1)), expected)),
+ test_desc);
+
diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValue/service-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValue/service-is-removed.https.window.js
new file mode 100644
index 0000000000..89c3112475
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/writeValue/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.writeValue(new ArrayBuffer(1 /* length */)), expected,
+ 'Service got removed.');
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValue/write-succeeds.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValue/write-succeeds.https.window.js
new file mode 100644
index 0000000000..b57fe941d0
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/writeValue/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.writeValue(typed_array);
+ ({lastValue, lastWriteType} =
+ await fake_characteristic.getLastWrittenValue());
+ assert_array_equals(lastValue, [1, 2]);
+ assert_equals(lastWriteType, 'default-deprecated');
+
+ await fake_characteristic.setNextWriteResponse(GATT_SUCCESS);
+
+ const array_buffer = Uint8Array.of(3, 4).buffer;
+ await characteristic.writeValue(array_buffer);
+ ({lastValue, lastWriteType} =
+ await fake_characteristic.getLastWrittenValue());
+ assert_array_equals(lastValue, [3, 4]);
+ assert_equals(lastWriteType, 'default-deprecated');
+
+ 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.writeValue(data_view);
+ ({lastValue, lastWriteType} =
+ await fake_characteristic.getLastWrittenValue());
+ assert_array_equals(lastValue, [5, 6]);
+ assert_equals(lastWriteType, 'default-deprecated');
+}, test_desc);
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);
diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/buffer-is-detached.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/buffer-is-detached.https.window.js
new file mode 100644
index 0000000000..75d4cf0805
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/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 =
+ 'writeValueWithoutResponse() 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.writeValueWithoutResponse(typed_array));
+
+ const array_buffer = Uint8Array.of(3, 4).buffer;
+ detachBuffer(array_buffer);
+ await promise_rejects_dom(
+ t, 'InvalidStateError',
+ characteristic.writeValueWithoutResponse(array_buffer));
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/characteristic-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/characteristic-is-removed.https.window.js
new file mode 100644
index 0000000000..8d3ed1f663
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/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.writeValueWithoutResponse(new ArrayBuffer(1 /* length */)),
+ expected, 'Characteristic got removed.');
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/gen-characteristic-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/gen-characteristic-is-removed.https.window.js
new file mode 100644
index 0000000000..b88246aae8
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/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.writeValueWithoutResponse(new Uint8Array(1)), expected)),
+ test_desc);
+
diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/service-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/service-is-removed.https.window.js
new file mode 100644
index 0000000000..feb711c64e
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/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.writeValueWithoutResponse(new ArrayBuffer(1 /* length */)),
+ expected, 'Service got removed.');
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/write-succeeds.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/write-succeeds.https.window.js
new file mode 100644
index 0000000000..0dcf8ad0b1
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/write-succeeds.https.window.js
@@ -0,0 +1,41 @@
+// 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');
+
+ const typed_array = Uint8Array.of(1, 2);
+ await characteristic.writeValueWithoutResponse(typed_array);
+ ({lastValue, lastWriteType} =
+ await fake_characteristic.getLastWrittenValue());
+ assert_array_equals(lastValue, [1, 2]);
+ assert_equals(lastWriteType, 'without-response');
+
+ const array_buffer = Uint8Array.of(3, 4).buffer;
+ await characteristic.writeValueWithoutResponse(array_buffer);
+ ({lastValue, lastWriteType} =
+ await fake_characteristic.getLastWrittenValue());
+ assert_array_equals(lastValue, [3, 4]);
+ assert_equals(lastWriteType, 'without-response');
+
+ const data_view = new DataView(new ArrayBuffer(2));
+ data_view.setUint8(0, 5);
+ data_view.setUint8(1, 6);
+ await characteristic.writeValueWithoutResponse(data_view);
+ ({lastValue, lastWriteType} =
+ await fake_characteristic.getLastWrittenValue());
+ assert_array_equals(lastValue, [5, 6]);
+ assert_equals(lastWriteType, 'without-response');
+}, test_desc);