diff --git a/components/bluetooth/lib.rs b/components/bluetooth/lib.rs index e3d4eba1a24..998053da577 100644 --- a/components/bluetooth/lib.rs +++ b/components/bluetooth/lib.rs @@ -628,6 +628,9 @@ impl BluetoothManager { device_id: String, uuid: String, sender: IpcSender>) { + if !self.cached_devices.contains_key(&device_id) { + return drop(sender.send(Err(BluetoothError::InvalidState))); + } let mut adapter = get_adapter_or_return_error!(self, sender); if !self.allowed_services.get(&device_id).map_or(false, |s| s.contains(&uuid)) { return drop(sender.send(Err(BluetoothError::Security))); @@ -654,6 +657,9 @@ impl BluetoothManager { device_id: String, uuid: Option, sender: IpcSender>) { + if !self.cached_devices.contains_key(&device_id) { + return drop(sender.send(Err(BluetoothError::InvalidState))); + } let mut adapter = get_adapter_or_return_error!(self, sender); let services = match uuid { Some(ref id) => { @@ -690,6 +696,9 @@ impl BluetoothManager { service_id: String, uuid: String, sender: IpcSender>) { + if !self.cached_services.contains_key(&service_id) { + return drop(sender.send(Err(BluetoothError::InvalidState))); + } let mut adapter = match self.get_or_create_adapter() { Some(a) => a, None => return drop(sender.send(Err(BluetoothError::Type(ADAPTER_ERROR.to_string())))), @@ -721,6 +730,9 @@ impl BluetoothManager { service_id: String, uuid: Option, sender: IpcSender>) { + if !self.cached_services.contains_key(&service_id) { + return drop(sender.send(Err(BluetoothError::InvalidState))); + } let mut adapter = match self.get_or_create_adapter() { Some(a) => a, None => return drop(sender.send(Err(BluetoothError::Type(ADAPTER_ERROR.to_string())))), @@ -758,6 +770,9 @@ impl BluetoothManager { service_id: String, uuid: String, sender: IpcSender>) { + if !self.cached_services.contains_key(&service_id) { + return drop(sender.send(Err(BluetoothError::InvalidState))); + } let mut adapter = get_adapter_or_return_error!(self, sender); let characteristics = self.get_gatt_characteristics_by_uuid(&mut adapter, &service_id, &uuid); if characteristics.is_empty() { @@ -789,6 +804,9 @@ impl BluetoothManager { service_id: String, uuid: Option, sender: IpcSender>) { + if !self.cached_services.contains_key(&service_id) { + return drop(sender.send(Err(BluetoothError::InvalidState))); + } let mut adapter = get_adapter_or_return_error!(self, sender); let characteristics = match uuid { Some(id) => self.get_gatt_characteristics_by_uuid(&mut adapter, &service_id, &id), @@ -828,6 +846,9 @@ impl BluetoothManager { characteristic_id: String, uuid: String, sender: IpcSender>) { + if !self.cached_characteristics.contains_key(&characteristic_id) { + return drop(sender.send(Err(BluetoothError::InvalidState))); + } let mut adapter = get_adapter_or_return_error!(self, sender); let descriptors = self.get_gatt_descriptors_by_uuid(&mut adapter, &characteristic_id, &uuid); if descriptors.is_empty() { @@ -848,6 +869,9 @@ impl BluetoothManager { characteristic_id: String, uuid: Option, sender: IpcSender>) { + if !self.cached_characteristics.contains_key(&characteristic_id) { + return drop(sender.send(Err(BluetoothError::InvalidState))); + } let mut adapter = get_adapter_or_return_error!(self, sender); let descriptors = match uuid { Some(id) => self.get_gatt_descriptors_by_uuid(&mut adapter, &characteristic_id, &id), @@ -879,7 +903,7 @@ impl BluetoothManager { value = self.get_gatt_descriptor(&mut adapter, &id) .map(|d| d.read_value().unwrap_or(vec![])); } - let _ = sender.send(value.ok_or(BluetoothError::NotSupported)); + let _ = sender.send(value.ok_or(BluetoothError::InvalidState)); } fn write_value(&mut self, id: String, value: Vec, sender: IpcSender>) { @@ -895,7 +919,7 @@ impl BluetoothManager { Ok(_) => Ok(true), Err(_) => return drop(sender.send(Err(BluetoothError::NotSupported))), }, - None => return drop(sender.send(Err(BluetoothError::NotSupported))), + None => return drop(sender.send(Err(BluetoothError::InvalidState))), }; let _ = sender.send(message); } diff --git a/components/bluetooth_traits/lib.rs b/components/bluetooth_traits/lib.rs index a1b1b41be6e..cea2a7b7a33 100644 --- a/components/bluetooth_traits/lib.rs +++ b/components/bluetooth_traits/lib.rs @@ -20,6 +20,7 @@ pub enum BluetoothError { NotFound, NotSupported, Security, + InvalidState, } #[derive(Deserialize, Serialize)] diff --git a/components/script/dom/bluetooth.rs b/components/script/dom/bluetooth.rs index b6f8544aeab..10809a4fd5d 100644 --- a/components/script/dom/bluetooth.rs +++ b/components/script/dom/bluetooth.rs @@ -289,6 +289,7 @@ impl From for Error { BluetoothError::NotFound => Error::NotFound, BluetoothError::NotSupported => Error::NotSupported, BluetoothError::Security => Error::Security, + BluetoothError::InvalidState => Error::InvalidState, } } } diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/getCharacteristic/service-is-removed.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/getCharacteristic/service-is-removed.html.ini deleted file mode 100644 index a53d4c55402..00000000000 --- a/tests/wpt/mozilla/meta/mozilla/bluetooth/getCharacteristic/service-is-removed.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[service-is-removed.html] - type: testharness - [Service is removed. Reject with InvalidStateError.] - expected: FAIL diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/getCharacteristics/service-is-removed-with-uuid.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/getCharacteristics/service-is-removed-with-uuid.html.ini deleted file mode 100644 index 9224f668cff..00000000000 --- a/tests/wpt/mozilla/meta/mozilla/bluetooth/getCharacteristics/service-is-removed-with-uuid.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[service-is-removed-with-uuid.html] - type: testharness - [Service is removed. Reject with InvalidStateError.] - expected: FAIL diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/getCharacteristics/service-is-removed.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/getCharacteristics/service-is-removed.html.ini deleted file mode 100644 index a53d4c55402..00000000000 --- a/tests/wpt/mozilla/meta/mozilla/bluetooth/getCharacteristics/service-is-removed.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[service-is-removed.html] - type: testharness - [Service is removed. Reject with InvalidStateError.] - expected: FAIL diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/getDescriptor/characteristic-is-removed.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/getDescriptor/characteristic-is-removed.html.ini deleted file mode 100644 index 0eefaf13656..00000000000 --- a/tests/wpt/mozilla/meta/mozilla/bluetooth/getDescriptor/characteristic-is-removed.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[characteristic-is-removed.html] - type: testharness - [Characteristic is removed. Reject with InvalidStateError.] - expected: FAIL diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/getDescriptors/characteristic-is-removed-with-uuid.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/getDescriptors/characteristic-is-removed-with-uuid.html.ini deleted file mode 100644 index ac0e362efc1..00000000000 --- a/tests/wpt/mozilla/meta/mozilla/bluetooth/getDescriptors/characteristic-is-removed-with-uuid.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[characteristic-is-removed-with-uuid.html] - type: testharness - [Characteristic is removed. Reject with InvalidStateError.] - expected: FAIL diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/getDescriptors/characteristic-is-removed.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/getDescriptors/characteristic-is-removed.html.ini deleted file mode 100644 index 0eefaf13656..00000000000 --- a/tests/wpt/mozilla/meta/mozilla/bluetooth/getDescriptors/characteristic-is-removed.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[characteristic-is-removed.html] - type: testharness - [Characteristic is removed. Reject with InvalidStateError.] - expected: FAIL diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/readValue/characteristic/characteristic-is-removed.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/readValue/characteristic/characteristic-is-removed.html.ini deleted file mode 100644 index 5d421d6b8c7..00000000000 --- a/tests/wpt/mozilla/meta/mozilla/bluetooth/readValue/characteristic/characteristic-is-removed.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[characteristic-is-removed.html] - type: testharness - [Characteristic gets removed. Reject with InvalidStateError.] - expected: FAIL diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/readValue/characteristic/service-is-removed.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/readValue/characteristic/service-is-removed.html.ini deleted file mode 100644 index d4ab00c8d6f..00000000000 --- a/tests/wpt/mozilla/meta/mozilla/bluetooth/readValue/characteristic/service-is-removed.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[service-is-removed.html] - type: testharness - [Service gets removed. Reject with InvalidStateError.] - expected: FAIL diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/readValue/descriptor/characteristic-is-removed.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/readValue/descriptor/characteristic-is-removed.html.ini deleted file mode 100644 index 5d421d6b8c7..00000000000 --- a/tests/wpt/mozilla/meta/mozilla/bluetooth/readValue/descriptor/characteristic-is-removed.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[characteristic-is-removed.html] - type: testharness - [Characteristic gets removed. Reject with InvalidStateError.] - expected: FAIL diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/readValue/descriptor/descriptor-is-removed.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/readValue/descriptor/descriptor-is-removed.html.ini deleted file mode 100644 index c59e14a44dc..00000000000 --- a/tests/wpt/mozilla/meta/mozilla/bluetooth/readValue/descriptor/descriptor-is-removed.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[descriptor-is-removed.html] - type: testharness - [Descriptor gets removed. Reject with InvalidStateError.] - expected: FAIL diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/readValue/descriptor/service-is-removed.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/readValue/descriptor/service-is-removed.html.ini deleted file mode 100644 index d4ab00c8d6f..00000000000 --- a/tests/wpt/mozilla/meta/mozilla/bluetooth/readValue/descriptor/service-is-removed.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[service-is-removed.html] - type: testharness - [Service gets removed. Reject with InvalidStateError.] - expected: FAIL diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/writeValue/characteristic/characteristic-is-removed.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/writeValue/characteristic/characteristic-is-removed.html.ini deleted file mode 100644 index 5d421d6b8c7..00000000000 --- a/tests/wpt/mozilla/meta/mozilla/bluetooth/writeValue/characteristic/characteristic-is-removed.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[characteristic-is-removed.html] - type: testharness - [Characteristic gets removed. Reject with InvalidStateError.] - expected: FAIL diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/writeValue/characteristic/service-is-removed.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/writeValue/characteristic/service-is-removed.html.ini deleted file mode 100644 index d4ab00c8d6f..00000000000 --- a/tests/wpt/mozilla/meta/mozilla/bluetooth/writeValue/characteristic/service-is-removed.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[service-is-removed.html] - type: testharness - [Service gets removed. Reject with InvalidStateError.] - expected: FAIL diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/writeValue/descriptor/characteristic-is-removed.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/writeValue/descriptor/characteristic-is-removed.html.ini deleted file mode 100644 index 5d421d6b8c7..00000000000 --- a/tests/wpt/mozilla/meta/mozilla/bluetooth/writeValue/descriptor/characteristic-is-removed.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[characteristic-is-removed.html] - type: testharness - [Characteristic gets removed. Reject with InvalidStateError.] - expected: FAIL diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/writeValue/descriptor/descriptor-is-removed.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/writeValue/descriptor/descriptor-is-removed.html.ini deleted file mode 100644 index c59e14a44dc..00000000000 --- a/tests/wpt/mozilla/meta/mozilla/bluetooth/writeValue/descriptor/descriptor-is-removed.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[descriptor-is-removed.html] - type: testharness - [Descriptor gets removed. Reject with InvalidStateError.] - expected: FAIL diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/writeValue/descriptor/service-is-removed.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/writeValue/descriptor/service-is-removed.html.ini deleted file mode 100644 index d4ab00c8d6f..00000000000 --- a/tests/wpt/mozilla/meta/mozilla/bluetooth/writeValue/descriptor/service-is-removed.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[service-is-removed.html] - type: testharness - [Service gets removed. Reject with InvalidStateError.] - expected: FAIL