aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAttila Dusnoki <dati91@gmail.com>2016-11-14 17:51:41 +0100
committerKeith Yeung <kungfukeith11@gmail.com>2016-11-23 01:24:33 -0800
commitfd7cdbf19fd4ad6ddb173d4b4061c3098ef29520 (patch)
treed1e962d51dfb16a5826cf9c9c353d31d3e3c2b8b
parenta89ba50180532bc652db7ff649f252ffdca33177 (diff)
downloadservo-fd7cdbf19fd4ad6ddb173d4b4061c3098ef29520.tar.gz
servo-fd7cdbf19fd4ad6ddb173d4b4061c3098ef29520.zip
Add Start/Stop notifications
-rw-r--r--components/bluetooth/lib.rs24
-rw-r--r--components/bluetooth/test.rs7
-rw-r--r--components/bluetooth_traits/lib.rs2
-rw-r--r--components/script/dom/bluetoothremotegattcharacteristic.rs44
-rw-r--r--components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl4
-rw-r--r--tests/wpt/mozilla/meta/MANIFEST.json60
-rw-r--r--tests/wpt/mozilla/meta/mozilla/bluetooth/startNotifications/disconnect-called-during.html.ini4
-rw-r--r--tests/wpt/mozilla/meta/mozilla/bluetooth/stopNotifications/disconnect-called-during.html.ini4
-rw-r--r--tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/blocklisted-characteristic.html17
-rw-r--r--tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/characteristic-is-removed.html21
-rw-r--r--tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/disconnect-called-before.html23
-rw-r--r--tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/disconnect-called-during.html24
-rw-r--r--tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/notify-failure.html20
-rw-r--r--tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/notify-succeeds.html21
-rw-r--r--tests/wpt/mozilla/tests/mozilla/bluetooth/stopNotifications/characteristic-is-removed.html22
-rw-r--r--tests/wpt/mozilla/tests/mozilla/bluetooth/stopNotifications/disconnect-called-before.html24
-rw-r--r--tests/wpt/mozilla/tests/mozilla/bluetooth/stopNotifications/disconnect-called-during.html25
-rw-r--r--tests/wpt/mozilla/tests/mozilla/bluetooth/stopNotifications/notify-succeeds.html22
18 files changed, 364 insertions, 4 deletions
diff --git a/components/bluetooth/lib.rs b/components/bluetooth/lib.rs
index c96ae6f88a7..44897d82d40 100644
--- a/components/bluetooth/lib.rs
+++ b/components/bluetooth/lib.rs
@@ -238,6 +238,9 @@ impl BluetoothManager {
BluetoothRequest::WriteValue(id, value, sender) => {
self.write_value(id, value, sender)
},
+ BluetoothRequest::EnableNotification(id, enable, sender) => {
+ self.enable_notification(id, enable, sender)
+ },
BluetoothRequest::Test(data_set_name, sender) => {
self.test(data_set_name, sender)
}
@@ -940,4 +943,25 @@ impl BluetoothManager {
None => return drop(sender.send(Err(BluetoothError::InvalidState))),
}
}
+
+ // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-startnotifications
+ fn enable_notification(&mut self, id: String, enable: bool, sender: IpcSender<BluetoothResponseResult>) {
+ let mut adapter = get_adapter_or_return_error!(self, sender);
+ match self.get_gatt_characteristic(&mut adapter, &id) {
+ Some(c) => {
+ let result = match enable {
+ true => c.start_notify(),
+ false => c.stop_notify(),
+ };
+ match result {
+ // Step 11.
+ Ok(_) => return drop(sender.send(Ok(BluetoothResponse::EnableNotification(())))),
+ // Step 4.
+ Err(_) => return drop(sender.send(Err(BluetoothError::NotSupported))),
+ }
+ },
+ // Step 3.
+ None => return drop(sender.send(Err(BluetoothError::InvalidState))),
+ }
+ }
}
diff --git a/components/bluetooth/test.rs b/components/bluetooth/test.rs
index ee84fcc976a..fa61c99d22b 100644
--- a/components/bluetooth/test.rs
+++ b/components/bluetooth/test.rs
@@ -18,6 +18,7 @@ const ADAPTER_ERROR: &'static str = "No adapter found";
const WRONG_DATA_SET_ERROR: &'static str = "Wrong data set name was provided";
const READ_FLAG: &'static str = "read";
const WRITE_FLAG: &'static str = "write";
+const NOTIFY_FLAG: &'static str = "notify";
// Adapter names
// https://cs.chromium.org/chromium/src/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.h?l=65
@@ -217,10 +218,11 @@ fn create_heart_rate_service(device: &BluetoothDevice,
}
// Heart Rate Measurement Characteristic
- let _heart_rate_measurement_characteristic =
+ let heart_rate_measurement_characteristic =
try!(create_characteristic_with_value(&heart_rate_service,
HEART_RATE_MEASUREMENT_CHARACTERISTIC_UUID.to_owned(),
vec![0]));
+ try!(heart_rate_measurement_characteristic.set_flags(vec![NOTIFY_FLAG.to_string()]));
// Body Sensor Location Characteristic 1
let body_sensor_location_characteristic_1 =
@@ -357,10 +359,11 @@ fn create_two_heart_rate_services_device(adapter: &BluetoothAdapter) -> Result<(
let heart_rate_service_empty_2 = try!(create_heart_rate_service(&heart_rate_device_empty, true));
- let _heart_rate_measurement_characteristic =
+ let heart_rate_measurement_characteristic =
try!(create_characteristic_with_value(&heart_rate_service_empty_1,
HEART_RATE_MEASUREMENT_CHARACTERISTIC_UUID.to_owned(),
vec![0]));
+ try!(heart_rate_measurement_characteristic.set_flags(vec![NOTIFY_FLAG.to_string()]));
let _body_sensor_location_characteristic_1 =
try!(create_characteristic_with_value(&heart_rate_service_empty_1,
diff --git a/components/bluetooth_traits/lib.rs b/components/bluetooth_traits/lib.rs
index de07a9f4fd7..5c06e900141 100644
--- a/components/bluetooth_traits/lib.rs
+++ b/components/bluetooth_traits/lib.rs
@@ -92,6 +92,7 @@ pub enum BluetoothRequest {
GetDescriptors(String, Option<String>, IpcSender<BluetoothResponseResult>),
ReadValue(String, IpcSender<BluetoothResponseResult>),
WriteValue(String, Vec<u8>, IpcSender<BluetoothResponseResult>),
+ EnableNotification(String, bool, IpcSender<BluetoothResponseResult>),
Test(String, IpcSender<BluetoothResult<()>>),
Exit,
}
@@ -110,6 +111,7 @@ pub enum BluetoothResponse {
GetDescriptors(BluetoothDescriptorsMsg),
ReadValue(Vec<u8>),
WriteValue(Vec<u8>),
+ EnableNotification(()),
}
pub trait BluetoothResponseListener {
diff --git a/components/script/dom/bluetoothremotegattcharacteristic.rs b/components/script/dom/bluetoothremotegattcharacteristic.rs
index dae5fd3e558..390878342db 100644
--- a/components/script/dom/bluetoothremotegattcharacteristic.rs
+++ b/components/script/dom/bluetoothremotegattcharacteristic.rs
@@ -214,6 +214,47 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
BluetoothRequest::WriteValue(self.get_instance_id(), value, sender)).unwrap();
return p;
}
+
+ #[allow(unrooted_must_root)]
+ // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-startnotifications
+ fn StartNotifications(&self) -> Rc<Promise> {
+ let p = Promise::new(&self.global());
+ let p_cx = p.global().get_cx();
+ // Step 1.
+ if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Reads) {
+ p.reject_error(p_cx, Security);
+ return p;
+ }
+ // Step 3.
+ if !(self.Properties().Notify() ||
+ self.Properties().Indicate()) {
+ p.reject_error(p_cx, NotSupported);
+ return p;
+ }
+ // Step 6.
+ if !self.Service().Device().Gatt().Connected() {
+ p.reject_error(p_cx, Network);
+ return p;
+ }
+ let sender = response_async(&p, self);
+ self.get_bluetooth_thread().send(
+ BluetoothRequest::EnableNotification(self.get_instance_id(),
+ true,
+ sender)).unwrap();
+ return p;
+ }
+
+ #[allow(unrooted_must_root)]
+ // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-stopnotifications
+ fn StopNotifications(&self) -> Rc<Promise> {
+ let p = Promise::new(&self.global());
+ let sender = response_async(&p, self);
+ self.get_bluetooth_thread().send(
+ BluetoothRequest::EnableNotification(self.get_instance_id(),
+ false,
+ sender)).unwrap();
+ return p;
+ }
}
impl AsyncBluetoothListener for BluetoothRemoteGATTCharacteristic {
@@ -263,6 +304,9 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTCharacteristic {
*self.value.borrow_mut() = Some(value.clone());
promise.resolve_native(promise_cx, &value);
},
+ BluetoothResponse::EnableNotification(_result) => {
+ promise.resolve_native(promise_cx, self);
+ },
_ => promise.reject_error(promise_cx, Error::Type("Something went wrong...".to_owned())),
}
}
diff --git a/components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl b/components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl
index 596a1095457..d1d937475b4 100644
--- a/components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl
+++ b/components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl
@@ -17,8 +17,8 @@ interface BluetoothRemoteGATTCharacteristic {
//Promise<DataView> readValue();
Promise<void> writeValue(sequence<octet> value);
//Promise<void> writeValue(BufferSource value);
- //Promise<void> startNotifications();
- //Promise<void> stopNotifications();
+ Promise<BluetoothRemoteGATTCharacteristic> startNotifications();
+ Promise<BluetoothRemoteGATTCharacteristic> stopNotifications();
};
//BluetootRemoteGATTCharacteristic implements EventTarget;
diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json
index a1b285c21ba..7aafa16f43f 100644
--- a/tests/wpt/mozilla/meta/MANIFEST.json
+++ b/tests/wpt/mozilla/meta/MANIFEST.json
@@ -7592,6 +7592,66 @@
"url": "/_mozilla/mozilla/bluetooth/requestDevice/two-filters.html"
}
],
+ "mozilla/bluetooth/startNotifications/blocklisted-characteristic.html": [
+ {
+ "path": "mozilla/bluetooth/startNotifications/blocklisted-characteristic.html",
+ "url": "/_mozilla/mozilla/bluetooth/startNotifications/blocklisted-characteristic.html"
+ }
+ ],
+ "mozilla/bluetooth/startNotifications/characteristic-is-removed.html": [
+ {
+ "path": "mozilla/bluetooth/startNotifications/characteristic-is-removed.html",
+ "url": "/_mozilla/mozilla/bluetooth/startNotifications/characteristic-is-removed.html"
+ }
+ ],
+ "mozilla/bluetooth/startNotifications/disconnect-called-before.html": [
+ {
+ "path": "mozilla/bluetooth/startNotifications/disconnect-called-before.html",
+ "url": "/_mozilla/mozilla/bluetooth/startNotifications/disconnect-called-before.html"
+ }
+ ],
+ "mozilla/bluetooth/startNotifications/disconnect-called-during.html": [
+ {
+ "path": "mozilla/bluetooth/startNotifications/disconnect-called-during.html",
+ "url": "/_mozilla/mozilla/bluetooth/startNotifications/disconnect-called-during.html"
+ }
+ ],
+ "mozilla/bluetooth/startNotifications/notify-failure.html": [
+ {
+ "path": "mozilla/bluetooth/startNotifications/notify-failure.html",
+ "url": "/_mozilla/mozilla/bluetooth/startNotifications/notify-failure.html"
+ }
+ ],
+ "mozilla/bluetooth/startNotifications/notify-succeeds.html": [
+ {
+ "path": "mozilla/bluetooth/startNotifications/notify-succeeds.html",
+ "url": "/_mozilla/mozilla/bluetooth/startNotifications/notify-succeeds.html"
+ }
+ ],
+ "mozilla/bluetooth/stopNotifications/characteristic-is-removed.html": [
+ {
+ "path": "mozilla/bluetooth/stopNotifications/characteristic-is-removed.html",
+ "url": "/_mozilla/mozilla/bluetooth/stopNotifications/characteristic-is-removed.html"
+ }
+ ],
+ "mozilla/bluetooth/stopNotifications/disconnect-called-before.html": [
+ {
+ "path": "mozilla/bluetooth/stopNotifications/disconnect-called-before.html",
+ "url": "/_mozilla/mozilla/bluetooth/stopNotifications/disconnect-called-before.html"
+ }
+ ],
+ "mozilla/bluetooth/stopNotifications/disconnect-called-during.html": [
+ {
+ "path": "mozilla/bluetooth/stopNotifications/disconnect-called-during.html",
+ "url": "/_mozilla/mozilla/bluetooth/stopNotifications/disconnect-called-during.html"
+ }
+ ],
+ "mozilla/bluetooth/stopNotifications/notify-succeeds.html": [
+ {
+ "path": "mozilla/bluetooth/stopNotifications/notify-succeeds.html",
+ "url": "/_mozilla/mozilla/bluetooth/stopNotifications/notify-succeeds.html"
+ }
+ ],
"mozilla/bluetooth/writeValue/characteristic/blocklisted-characteristic.html": [
{
"path": "mozilla/bluetooth/writeValue/characteristic/blocklisted-characteristic.html",
diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/startNotifications/disconnect-called-during.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/startNotifications/disconnect-called-during.html.ini
new file mode 100644
index 00000000000..3f7bd5bd0e3
--- /dev/null
+++ b/tests/wpt/mozilla/meta/mozilla/bluetooth/startNotifications/disconnect-called-during.html.ini
@@ -0,0 +1,4 @@
+[disconnect-called-during.html]
+ type: testharness
+ [disconnect() called during startNotifications. Reject with NetworkError.]
+ expected: FAIL
diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/stopNotifications/disconnect-called-during.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/stopNotifications/disconnect-called-during.html.ini
new file mode 100644
index 00000000000..63d2902e525
--- /dev/null
+++ b/tests/wpt/mozilla/meta/mozilla/bluetooth/stopNotifications/disconnect-called-during.html.ini
@@ -0,0 +1,4 @@
+[disconnect-called-during.html]
+ type: testharness
+ [disconnect() called during stopNotifications. Reject with NetworkError.]
+ expected: FAIL
diff --git a/tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/blocklisted-characteristic.html b/tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/blocklisted-characteristic.html
new file mode 100644
index 00000000000..df04ae6bb1e
--- /dev/null
+++ b/tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/blocklisted-characteristic.html
@@ -0,0 +1,17 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
+<script>
+'use strict';
+promise_test(t => {
+ window.testRunner.setBluetoothMockDataSet(adapter_type.blocklist);
+ return window.navigator.bluetooth.requestDevice({
+ filters: [{services: [blocklist_test_service_uuid]}]
+ })
+ .then(device => device.gatt.connect())
+ .then(gattServer => gattServer.getPrimaryService(blocklist_test_service_uuid))
+ .then(service => service.getCharacteristic(blocklist_exclude_reads_characteristic_uuid))
+ .then(characteristic => promise_rejects(t, 'SecurityError', characteristic.startNotifications()));
+}, 'Characteristic with exclude-reads rejects startNotifications.');
+</script>
diff --git a/tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/characteristic-is-removed.html b/tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/characteristic-is-removed.html
new file mode 100644
index 00000000000..f305b88c1b7
--- /dev/null
+++ b/tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/characteristic-is-removed.html
@@ -0,0 +1,21 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
+<script>
+'use strict';
+promise_test(t => {
+ window.testRunner.setBluetoothMockDataSet(adapter_type.heart_rate);
+ return window.navigator.bluetooth.requestDevice({
+ filters: [{services: [heart_rate.name]}],
+ optionalServices: [generic_access.name]
+ })
+ .then(device => device.gatt.connect())
+ .then(gattServer => gattServer.getPrimaryService(heart_rate.name))
+ .then(service => service.getCharacteristic(heart_rate_measurement.name))
+ .then(characteristic => {
+ window.testRunner.setBluetoothMockDataSet(adapter_type.missing_characteristic_heart_rate);
+ return promise_rejects(t, 'InvalidStateError', characteristic.startNotifications());
+ });
+}, 'Characteristic gets removed. Reject with InvalidStateError.');
+</script>
diff --git a/tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/disconnect-called-before.html b/tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/disconnect-called-before.html
new file mode 100644
index 00000000000..879129b835a
--- /dev/null
+++ b/tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/disconnect-called-before.html
@@ -0,0 +1,23 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
+<script>
+'use strict';
+promise_test(t => {
+ window.testRunner.setBluetoothMockDataSet(adapter_type.heart_rate);
+ return window.navigator.bluetooth.requestDevice({
+ filters: [{services: [heart_rate.name]}],
+ optionalServices: [generic_access.name]
+ })
+ .then(device => device.gatt.connect())
+ .then(gattServer => {
+ return gattServer.getPrimaryService(heart_rate.name)
+ .then(service => service.getCharacteristic(heart_rate_measurement.name))
+ .then(characteristic => {
+ gattServer.disconnect();
+ return promise_rejects(t, 'NetworkError', characteristic.startNotifications());
+ });
+ });
+}, 'disconnect() called before startNotifications. Reject with NetworkError.');
+</script>
diff --git a/tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/disconnect-called-during.html b/tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/disconnect-called-during.html
new file mode 100644
index 00000000000..61597a8795b
--- /dev/null
+++ b/tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/disconnect-called-during.html
@@ -0,0 +1,24 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
+<script>
+'use strict';
+promise_test(t => {
+ window.testRunner.setBluetoothMockDataSet(adapter_type.heart_rate);
+ return window.navigator.bluetooth.requestDevice({
+ filters: [{services: [heart_rate.name]}],
+ optionalServices: [generic_access.name]
+ })
+ .then(device => device.gatt.connect())
+ .then(gattServer => {
+ return gattServer.getPrimaryService(heart_rate.name)
+ .then(service => service.getCharacteristic(heart_rate_measurement.name))
+ .then(characteristic => {
+ let promise = promise_rejects(t, 'NetworkError', characteristic.startNotifications());
+ gattServer.disconnect();
+ return promise;
+ });
+ });
+}, 'disconnect() called during startNotifications. Reject with NetworkError.');
+</script>
diff --git a/tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/notify-failure.html b/tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/notify-failure.html
new file mode 100644
index 00000000000..2ffb189a283
--- /dev/null
+++ b/tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/notify-failure.html
@@ -0,0 +1,20 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
+<script>
+'use strict';
+promise_test(t => {
+ window.testRunner.setBluetoothMockDataSet(adapter_type.heart_rate);
+ return window.navigator.bluetooth.requestDevice({
+ filters: [{services: [heart_rate.name]}],
+ optionalServices: [generic_access.name]
+ })
+ .then(device => device.gatt.connect())
+ .then(gattServer => {
+ return gattServer.getPrimaryService(generic_access.name)
+ .then(service => service.getCharacteristic(device_name.name))
+ .then(characteristic => promise_rejects(t, 'NotSupportedError', characteristic.startNotifications()));
+ });
+}, 'startNotifications should throw NotSupportedError without Notify or Indicate flag.');
+</script>
diff --git a/tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/notify-succeeds.html b/tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/notify-succeeds.html
new file mode 100644
index 00000000000..33644d3f4a6
--- /dev/null
+++ b/tests/wpt/mozilla/tests/mozilla/bluetooth/startNotifications/notify-succeeds.html
@@ -0,0 +1,21 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
+<script>
+'use strict';
+promise_test(() => {
+ window.testRunner.setBluetoothMockDataSet(adapter_type.heart_rate);
+ return window.navigator.bluetooth.requestDevice({
+ filters: [{services: [heart_rate.name]}],
+ optionalServices: [generic_access.name]
+ })
+ .then(device => device.gatt.connect())
+ .then(gattServer => gattServer.getPrimaryService(heart_rate.name))
+ .then(service => service.getCharacteristic(heart_rate_measurement.name))
+ .then(characteristic => {
+ return characteristic.startNotifications()
+ .then(result => assert_equals(result, characteristic));
+ });
+}, 'startNotifications should return the caller object.');
+</script>
diff --git a/tests/wpt/mozilla/tests/mozilla/bluetooth/stopNotifications/characteristic-is-removed.html b/tests/wpt/mozilla/tests/mozilla/bluetooth/stopNotifications/characteristic-is-removed.html
new file mode 100644
index 00000000000..3b691ff10e4
--- /dev/null
+++ b/tests/wpt/mozilla/tests/mozilla/bluetooth/stopNotifications/characteristic-is-removed.html
@@ -0,0 +1,22 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
+<script>
+'use strict';
+promise_test(t => {
+ window.testRunner.setBluetoothMockDataSet(adapter_type.heart_rate);
+ return window.navigator.bluetooth.requestDevice({
+ filters: [{services: [heart_rate.name]}],
+ optionalServices: [generic_access.name]
+ })
+ .then(device => device.gatt.connect())
+ .then(gattServer => gattServer.getPrimaryService(heart_rate.name))
+ .then(service => service.getCharacteristic(heart_rate_measurement.name))
+ .then(characteristic => characteristic.startNotifications())
+ .then(characteristic => {
+ window.testRunner.setBluetoothMockDataSet(adapter_type.missing_characteristic_heart_rate);
+ return promise_rejects(t, 'InvalidStateError', characteristic.stopNotifications());
+ });
+}, 'Characteristic gets removed. Reject with InvalidStateError.');
+</script>
diff --git a/tests/wpt/mozilla/tests/mozilla/bluetooth/stopNotifications/disconnect-called-before.html b/tests/wpt/mozilla/tests/mozilla/bluetooth/stopNotifications/disconnect-called-before.html
new file mode 100644
index 00000000000..edcf89c2cc6
--- /dev/null
+++ b/tests/wpt/mozilla/tests/mozilla/bluetooth/stopNotifications/disconnect-called-before.html
@@ -0,0 +1,24 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
+<script>
+'use strict';
+promise_test(t => {
+ window.testRunner.setBluetoothMockDataSet(adapter_type.heart_rate);
+ return window.navigator.bluetooth.requestDevice({
+ filters: [{services: [heart_rate.name]}],
+ optionalServices: [generic_access.name]
+ })
+ .then(device => device.gatt.connect())
+ .then(gattServer => {
+ return gattServer.getPrimaryService(heart_rate.name)
+ .then(service => service.getCharacteristic(heart_rate_measurement.name))
+ .then(characteristic => characteristic.startNotifications())
+ .then(characteristic => {
+ gattServer.disconnect();
+ return promise_rejects(t, 'NetworkError', characteristic.startNotifications());
+ });
+ });
+}, 'disconnect() called before stopNotifications. Reject with NetworkError.');
+</script>
diff --git a/tests/wpt/mozilla/tests/mozilla/bluetooth/stopNotifications/disconnect-called-during.html b/tests/wpt/mozilla/tests/mozilla/bluetooth/stopNotifications/disconnect-called-during.html
new file mode 100644
index 00000000000..a10f9c1f116
--- /dev/null
+++ b/tests/wpt/mozilla/tests/mozilla/bluetooth/stopNotifications/disconnect-called-during.html
@@ -0,0 +1,25 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
+<script>
+'use strict';
+promise_test(t => {
+ window.testRunner.setBluetoothMockDataSet(adapter_type.heart_rate);
+ return window.navigator.bluetooth.requestDevice({
+ filters: [{services: [heart_rate.name]}],
+ optionalServices: [generic_access.name]
+ })
+ .then(device => device.gatt.connect())
+ .then(gattServer => {
+ return gattServer.getPrimaryService(heart_rate.name)
+ .then(service => service.getCharacteristic(heart_rate_measurement.name))
+ .then(characteristic => characteristic.startNotifications())
+ .then(characteristic => {
+ let promise = promise_rejects(t, 'NetworkError', characteristic.startNotifications());
+ gattServer.disconnect();
+ return promise;
+ });
+ });
+}, 'disconnect() called during stopNotifications. Reject with NetworkError.');
+</script>
diff --git a/tests/wpt/mozilla/tests/mozilla/bluetooth/stopNotifications/notify-succeeds.html b/tests/wpt/mozilla/tests/mozilla/bluetooth/stopNotifications/notify-succeeds.html
new file mode 100644
index 00000000000..c4047b0eede
--- /dev/null
+++ b/tests/wpt/mozilla/tests/mozilla/bluetooth/stopNotifications/notify-succeeds.html
@@ -0,0 +1,22 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
+<script>
+'use strict';
+promise_test(() => {
+ window.testRunner.setBluetoothMockDataSet(adapter_type.heart_rate);
+ return window.navigator.bluetooth.requestDevice({
+ filters: [{services: [heart_rate.name]}],
+ optionalServices: [generic_access.name]
+ })
+ .then(device => device.gatt.connect())
+ .then(gattServer => gattServer.getPrimaryService(heart_rate.name))
+ .then(service => service.getCharacteristic(heart_rate_measurement.name))
+ .then(characteristic => characteristic.startNotifications())
+ .then(characteristic => {
+ return characteristic.stopNotifications()
+ .then(result => assert_equals(result, characteristic));
+ });
+}, 'stopNotifications should return the caller object.');
+</script>