aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-12-14 15:29:43 -0800
committerGitHub <noreply@github.com>2016-12-14 15:29:43 -0800
commit6ee175bf705108ab25e80521d7be84b5e58ef698 (patch)
treeb16a4ac9e07dad37cfff27facb7745b60025a87f
parenteb1bd596822c7e24589fdc08c4f41c69c4207351 (diff)
parentc3e771274a66745f4715e3ef5160dc310c0e29b7 (diff)
downloadservo-6ee175bf705108ab25e80521d7be84b5e58ef698.tar.gz
servo-6ee175bf705108ab25e80521d7be84b5e58ef698.zip
Auto merge of #14567 - szeged:represented-attributes, r=jdm
Check if represented attributes are cached <!-- Please describe your changes on the following line: --> Improve existing cache checks in `/bluetooth/lib.rs`, and update Step comments in `script/dom` corresponding to this. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] There are tests for these changes OR <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14567) <!-- Reviewable:end -->
-rw-r--r--components/bluetooth/lib.rs38
-rw-r--r--components/script/dom/bluetoothremotegattcharacteristic.rs31
-rw-r--r--components/script/dom/bluetoothremotegattdescriptor.rs12
-rw-r--r--components/script/dom/bluetoothremotegattserver.rs17
-rw-r--r--components/script/dom/bluetoothremotegattservice.rs16
-rw-r--r--tests/wpt/mozilla/meta/mozilla/bluetooth/connect/device-goes-out-of-range.html.ini5
6 files changed, 53 insertions, 66 deletions
diff --git a/components/bluetooth/lib.rs b/components/bluetooth/lib.rs
index 47f3d89b011..e3045be4248 100644
--- a/components/bluetooth/lib.rs
+++ b/components/bluetooth/lib.rs
@@ -421,6 +421,10 @@ impl BluetoothManager {
}
}
+ fn device_is_cached(&self, device_id: &str) -> bool {
+ self.cached_devices.contains_key(device_id) && self.address_to_id.values().any(|v| v == device_id)
+ }
+
// Service
fn get_and_cache_gatt_services(&mut self,
@@ -463,6 +467,10 @@ impl BluetoothManager {
services.into_iter().filter(|s| s.get_uuid().ok() == Some(service_uuid.to_string())).collect()
}
+ fn service_is_cached(&self, service_id: &str) -> bool {
+ self.cached_services.contains_key(service_id) && self.service_to_device.contains_key(service_id)
+ }
+
// Characteristic
fn get_and_cache_gatt_characteristics(&mut self,
@@ -527,6 +535,11 @@ impl BluetoothManager {
props
}
+ fn characteristic_is_cached(&self, characteristic_id: &str) -> bool {
+ self.cached_characteristics.contains_key(characteristic_id) &&
+ self.characteristic_to_service.contains_key(characteristic_id)
+ }
+
// Descriptor
fn get_and_cache_gatt_descriptors(&mut self,
@@ -627,6 +640,10 @@ impl BluetoothManager {
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect
fn gatt_server_connect(&mut self, device_id: String, sender: IpcSender<BluetoothResponseResult>) {
+ // Step 2.
+ if !self.device_is_cached(&device_id) {
+ return drop(sender.send(Err(BluetoothError::Network)));
+ }
let mut adapter = get_adapter_or_return_error!(self, sender);
// Step 5.1.1.
@@ -685,7 +702,7 @@ impl BluetoothManager {
uuid: String,
sender: IpcSender<BluetoothResponseResult>) {
// Step 5.
- if !self.cached_devices.contains_key(&device_id) {
+ if !self.device_is_cached(&device_id) {
return drop(sender.send(Err(BluetoothError::InvalidState)));
}
let mut adapter = get_adapter_or_return_error!(self, sender);
@@ -721,7 +738,7 @@ impl BluetoothManager {
uuid: Option<String>,
sender: IpcSender<BluetoothResponseResult>) {
// Step 5.
- if !self.cached_devices.contains_key(&device_id) {
+ if !self.device_is_cached(&device_id) {
return drop(sender.send(Err(BluetoothError::InvalidState)));
}
let mut adapter = get_adapter_or_return_error!(self, sender);
@@ -766,7 +783,7 @@ impl BluetoothManager {
uuid: String,
sender: IpcSender<BluetoothResponseResult>) {
// Step 5.
- if !self.cached_services.contains_key(&service_id) {
+ if !self.service_is_cached(&service_id) {
return drop(sender.send(Err(BluetoothError::InvalidState)));
}
let mut adapter = get_adapter_or_return_error!(self, sender);
@@ -807,7 +824,7 @@ impl BluetoothManager {
uuid: Option<String>,
sender: IpcSender<BluetoothResponseResult>) {
// Step 5.
- if !self.cached_services.contains_key(&service_id) {
+ if !self.service_is_cached(&service_id) {
return drop(sender.send(Err(BluetoothError::InvalidState)));
}
let mut adapter = get_adapter_or_return_error!(self, sender);
@@ -854,7 +871,7 @@ impl BluetoothManager {
uuid: String,
sender: IpcSender<BluetoothResponseResult>) {
// Step 5.
- if !self.cached_services.contains_key(&service_id) {
+ if !self.service_is_cached(&service_id) {
return drop(sender.send(Err(BluetoothError::InvalidState)));
}
let mut adapter = get_adapter_or_return_error!(self, sender);
@@ -891,7 +908,7 @@ impl BluetoothManager {
uuid: Option<String>,
sender: IpcSender<BluetoothResponseResult>) {
// Step 5.
- if !self.cached_services.contains_key(&service_id) {
+ if !self.service_is_cached(&service_id) {
return drop(sender.send(Err(BluetoothError::InvalidState)));
}
let mut adapter = get_adapter_or_return_error!(self, sender);
@@ -938,7 +955,7 @@ impl BluetoothManager {
uuid: String,
sender: IpcSender<BluetoothResponseResult>) {
// Step 5.
- if !self.cached_characteristics.contains_key(&characteristic_id) {
+ if !self.characteristic_is_cached(&characteristic_id) {
return drop(sender.send(Err(BluetoothError::InvalidState)));
}
let mut adapter = get_adapter_or_return_error!(self, sender);
@@ -968,7 +985,7 @@ impl BluetoothManager {
uuid: Option<String>,
sender: IpcSender<BluetoothResponseResult>) {
// Step 5.
- if !self.cached_characteristics.contains_key(&characteristic_id) {
+ if !self.characteristic_is_cached(&characteristic_id) {
return drop(sender.send(Err(BluetoothError::InvalidState)));
}
let mut adapter = get_adapter_or_return_error!(self, sender);
@@ -1069,6 +1086,11 @@ impl BluetoothManager {
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-startnotifications
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-stopnotifications
fn enable_notification(&mut self, id: String, enable: bool, sender: IpcSender<BluetoothResponseResult>) {
+ // (StartNotifications) Step 2 - 3.
+ // (StopNotifications) Step 1 - 2.
+ if !self.characteristic_is_cached(&id) {
+ return drop(sender.send(Err(BluetoothError::InvalidState)));
+ }
// (StartNotification) TODO: Step 7: Missing because it is optional.
let mut adapter = get_adapter_or_return_error!(self, sender);
match self.get_gatt_characteristic(&mut adapter, &id) {
diff --git a/components/script/dom/bluetoothremotegattcharacteristic.rs b/components/script/dom/bluetoothremotegattcharacteristic.rs
index 6ac48edcf86..a1de986b714 100644
--- a/components/script/dom/bluetoothremotegattcharacteristic.rs
+++ b/components/script/dom/bluetoothremotegattcharacteristic.rs
@@ -128,9 +128,7 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
return p;
}
- // TODO: Step 5: Implement representedService internal slot for BluetoothRemoteGATTService.
-
- // Note: Steps 6 - 7 are implemented in components/bluetooth/lib.rs in get_descriptor function
+ // Note: Steps 5 - 7 are implemented in components/bluetooth/lib.rs in get_descriptor function
// and in handle_response function.
let sender = response_async(&p, self);
self.get_bluetooth_thread().send(
@@ -171,9 +169,7 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
return p;
}
- // TODO: Step 5: Implement representedService internal slot for BluetoothRemoteGATTService.
-
- // Note: Steps 6 - 7 are implemented in components/bluetooth/lib.rs in get_descriptors function
+ // Note: Steps 5 - 7 are implemented in components/bluetooth/lib.rs in get_descriptors function
// and in handle_response function.
let sender = response_async(&p, self);
self.get_bluetooth_thread().send(
@@ -204,8 +200,6 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
return p;
}
- // TODO: Step 3 - 4: Implement representedCharacteristic internal slot for BluetoothRemoteGATTCharacteristic.
-
// TODO: Step 5: Implement the `connection-checking-wrapper` algorithm for BluetoothRemoteGATTServer.
// Step 5.1.
@@ -214,8 +208,8 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
return p;
}
- // Note: Remaining substeps of Step 5 are implemented in components/bluetooth/lib.rs in readValue function
- // and in handle_response function.
+ // Note: Steps 3 - 4 and the remaining substeps of Step 5 are implemented in components/bluetooth/lib.rs
+ // in readValue function and in handle_response function.
let sender = response_async(&p, self);
self.get_bluetooth_thread().send(
BluetoothRequest::ReadValue(self.get_instance_id(), sender)).unwrap();
@@ -246,8 +240,6 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
return p;
}
- // TODO: Step 5 - 6: Implement representedCharacteristic internal slot for BluetoothRemoteGATTCharacteristic.
-
// TODO: Step 7: Implement the `connection-checking-wrapper` algorithm for BluetoothRemoteGATTServer.
// Step 7.1.
@@ -258,8 +250,8 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
return p;
}
- // Note: Remaining substeps of Step 7 are implemented in components/bluetooth/lib.rs in writeValue function
- // and in handle_response function.
+ // Note: Steps 5 - 6 and the remaining substeps of Step 7 are implemented in components/bluetooth/lib.rs
+ // in writeValue function and in handle_response function.
let sender = response_async(&p, self);
self.get_bluetooth_thread().send(
BluetoothRequest::WriteValue(self.get_instance_id(), value, sender)).unwrap();
@@ -278,8 +270,6 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
return p;
}
- // TODO: Step 2 - 3: Implement representedCharacteristic internal slot for BluetoothRemoteGATTCharacteristic.
-
// Step 4.
if !(self.Properties().Notify() ||
self.Properties().Indicate()) {
@@ -295,7 +285,7 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
return p;
}
- // Note: Steps 7 - 11 are implemented in components/bluetooth/lib.rs in enable_notification function
+ // Note: Steps 2 - 3, 7 - 11 are implemented in components/bluetooth/lib.rs in enable_notification function
// and in handle_response function.
let sender = response_async(&p, self);
self.get_bluetooth_thread().send(
@@ -311,11 +301,10 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
let p = Promise::new(&self.global());
let sender = response_async(&p, self);
- // TODO: Step 1 - 4: Implement representedCharacteristic internal slot and
- // `active notification context set` for BluetoothRemoteGATTCharacteristic,
+ // TODO: Step 3 - 4: Implement `active notification context set` for BluetoothRemoteGATTCharacteristic,
- // Note: Part of Step 4 and Step 5 are implemented in components/bluetooth/lib.rs in enable_notification
- // function and in handle_response function.
+ // Note: Steps 1 - 2, and part of Step 4 and Step 5 are implemented in components/bluetooth/lib.rs
+ // in enable_notification function and in handle_response function.
self.get_bluetooth_thread().send(
BluetoothRequest::EnableNotification(self.get_instance_id(),
false,
diff --git a/components/script/dom/bluetoothremotegattdescriptor.rs b/components/script/dom/bluetoothremotegattdescriptor.rs
index 541374e6841..b96a20c4a21 100644
--- a/components/script/dom/bluetoothremotegattdescriptor.rs
+++ b/components/script/dom/bluetoothremotegattdescriptor.rs
@@ -103,11 +103,9 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
return p;
}
- // TODO: Step 3 - 4: Implement representedDescriptor internal slot for BluetoothRemoteGATTDescriptor.
-
// TODO: Step 5: Implement the `connection-checking-wrapper` algorithm for BluetoothRemoteGATTServer.
- // Note: Substeps of Step 5 are implemented in components/bluetooth/lib.rs in readValue function
- // and in handle_response function.
+ // Note: Steps 3 - 4 and substeps of Step 5 are implemented in components/bluetooth/lib.rs
+ // in readValue function and in handle_response function.
let sender = response_async(&p, self);
self.get_bluetooth_thread().send(
BluetoothRequest::ReadValue(self.get_instance_id(), sender)).unwrap();
@@ -138,11 +136,9 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
return p;
}
- // TODO: Step 5 - 6: Implement representedCharacteristic internal slot for BluetoothRemoteGATTCharacteristic.
-
// TODO: Step 7: Implement the `connection-checking-wrapper` algorithm for BluetoothRemoteGATTServer.
- // Note: Substeps of Step 7 are implemented in components/bluetooth/lib.rs in writeValue function
- // and in handle_response function.
+ // Note: Steps 5 - 6 and substeps of Step 7 are implemented in components/bluetooth/lib.rs
+ // in writeValue function and in handle_response function.
let sender = response_async(&p, self);
self.get_bluetooth_thread().send(
BluetoothRequest::WriteValue(self.get_instance_id(), value, sender)).unwrap();
diff --git a/components/script/dom/bluetoothremotegattserver.rs b/components/script/dom/bluetoothremotegattserver.rs
index 72f7cd546d3..307c3b87f66 100644
--- a/components/script/dom/bluetoothremotegattserver.rs
+++ b/components/script/dom/bluetoothremotegattserver.rs
@@ -67,17 +67,14 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
let p = Promise::new(&self.global());
let sender = response_async(&p, self);
- // TODO: Step 2: Implement representedDevice internal slot for BluetoothDevice.
-
// TODO: Step 3: Check if the UA is currently using the Bluetooth system.
// TODO: Step 4: Implement activeAlgorithms internal slot for BluetoothRemoteGATTServer.
- // TODO: Step 5.1 - 5.2: Implement activeAlgorithms, representedDevice internal slots
- // and the` garbage-collect the connection` algorithm.
+ // TODO: Step 5.1 - 5.2: Implement activeAlgorithms internal slot for BluetoothRemoteGATTServer.
- // Note: Steps 5.1.1 and 5.1.3 are in components/bluetooth/lib.rs in the gatt_server_connect function.
- // Steps 5.2.4 - 5.2.5 are in response function.
+ // Note: Steps 2, 5.1.1 and 5.1.3 are in components/bluetooth/lib.rs in the gatt_server_connect function.
+ // Steps 5.2.3 - 5.2.5 are in response function.
self.get_bluetooth_thread().send(
BluetoothRequest::GATTServerConnect(String::from(self.Device().Id()), sender)).unwrap();
// Step 5: return promise.
@@ -142,9 +139,7 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
return p;
}
- // TODO: Step 5: Implement representedDevice internal slot for BluetoothDevice.
-
- // Note: Steps 6 - 7 are implemented in components/bluetooth/lib.rs in get_primary_service function
+ // Note: Steps 5 - 7 are implemented in components/bluetooth/lib.rs in get_primary_service function
// and in handle_response function.
let sender = response_async(&p, self);
self.get_bluetooth_thread().send(
@@ -185,9 +180,7 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
return p;
}
- // TODO: Step 5: Implement representedDevice internal slot for BluetoothDevice.
-
- // Note: Steps 6 - 7 are implemented in components/bluetooth/lib.rs in get_primary_services function
+ // Note: Steps 5 - 7 are implemented in components/bluetooth/lib.rs in get_primary_services function
// and in handle_response function.
let sender = response_async(&p, self);
self.get_bluetooth_thread().send(
diff --git a/components/script/dom/bluetoothremotegattservice.rs b/components/script/dom/bluetoothremotegattservice.rs
index 6881a78ff45..83f1a7f3040 100644
--- a/components/script/dom/bluetoothremotegattservice.rs
+++ b/components/script/dom/bluetoothremotegattservice.rs
@@ -117,9 +117,7 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
return p;
}
- // TODO: Step 5: Implement representedService internal slot for BluetootRemoteGATTService.
-
- // Note: Steps 6 - 7 are implemented is components/bluetooth/lib.rs in get_characteristic function
+ // Note: Steps 5 - 7 are implemented is components/bluetooth/lib.rs in get_characteristic function
// and in handle_response function.
let sender = response_async(&p, self);
self.get_bluetooth_thread().send(
@@ -160,9 +158,7 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
return p;
}
- // TODO: Step 5: Implement representedService internal slot for BluetootRemoteGATTService.
-
- // Note: Steps 6 - 7 are implemented is components/bluetooth/lib.rs in get_characteristics function
+ // Note: Steps 5 - 7 are implemented is components/bluetooth/lib.rs in get_characteristics function
// and in handle_response function.
let sender = response_async(&p, self);
self.get_bluetooth_thread().send(
@@ -200,9 +196,7 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
return p;
}
- // TODO: Step 5: Implement representedService internal slot for BluetootRemoteGATTService.
-
- // Note: Steps 6 - 7 are implemented is components/bluetooth/lib.rs in get_included_service function
+ // Note: Steps 5 - 7 are implemented is components/bluetooth/lib.rs in get_included_service function
// and in handle_response function.
let sender = response_async(&p, self);
self.get_bluetooth_thread().send(
@@ -246,9 +240,7 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
return p;
}
- // TODO: Step 5: Implement representedService internal slot for BluetootRemoteGATTService.
-
- // Note: Steps 6 - 7 are implemented is components/bluetooth/lib.rs in get_included_services function
+ // Note: Steps 5 - 7 are implemented is components/bluetooth/lib.rs in get_included_services function
// and in handle_response function.
let sender = response_async(&p, self);
self.get_bluetooth_thread().send(
diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/connect/device-goes-out-of-range.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/connect/device-goes-out-of-range.html.ini
deleted file mode 100644
index 1ac7e23518b..00000000000
--- a/tests/wpt/mozilla/meta/mozilla/bluetooth/connect/device-goes-out-of-range.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[device-goes-out-of-range.html]
- type: testharness
- [Device goes out of range. Reject with NetworkError.]
- expected: FAIL
-