From 4ed461c6e5e3349ec92c29c5a449b08b54503d90 Mon Sep 17 00:00:00 2001 From: zakorgyula Date: Fri, 7 Oct 2016 12:42:40 +0200 Subject: [PATCH] Accepting empty deviceName, when requesting a BluetoothDevice. --- components/bluetooth/lib.rs | 4 ++-- components/bluetooth_traits/scanfilter.rs | 12 ++++++------ components/script/dom/bluetooth.rs | 4 ++-- ...name-empty-device-from-name-empty-filter.html.ini | 4 ---- .../requestDevice/name-empty-filter.html.ini | 4 ---- ...me-missing-device-from-name-empty-filter.html.ini | 4 ---- 6 files changed, 10 insertions(+), 22 deletions(-) delete mode 100644 tests/wpt/mozilla/meta/mozilla/bluetooth/requestDevice/name-empty-device-from-name-empty-filter.html.ini delete mode 100644 tests/wpt/mozilla/meta/mozilla/bluetooth/requestDevice/name-empty-filter.html.ini delete mode 100644 tests/wpt/mozilla/meta/mozilla/bluetooth/requestDevice/name-missing-device-from-name-empty-filter.html.ini diff --git a/components/bluetooth/lib.rs b/components/bluetooth/lib.rs index 998053da577..5519d74f408 100644 --- a/components/bluetooth/lib.rs +++ b/components/bluetooth/lib.rs @@ -106,8 +106,8 @@ fn matches_filter(device: &BluetoothDevice, filter: &BluetoothScanfilter) -> boo } // Step 1. - if !filter.get_name().is_empty() { - if device.get_name().ok() != Some(filter.get_name().to_string()) { + if let Some(name) = filter.get_name() { + if device.get_name().ok() != Some(name.to_string()) { return false; } } diff --git a/components/bluetooth_traits/scanfilter.rs b/components/bluetooth_traits/scanfilter.rs index b5017de72ad..4d0da1ccb0d 100644 --- a/components/bluetooth_traits/scanfilter.rs +++ b/components/bluetooth_traits/scanfilter.rs @@ -25,7 +25,7 @@ impl ServiceUUIDSequence { #[derive(Deserialize, Serialize)] pub struct BluetoothScanfilter { - name: String, + name: Option, name_prefix: String, services: ServiceUUIDSequence, manufacturer_id: Option, @@ -33,7 +33,7 @@ pub struct BluetoothScanfilter { } impl BluetoothScanfilter { - pub fn new(name: String, + pub fn new(name: Option, name_prefix: String, services: Vec, manufacturer_id: Option, @@ -48,8 +48,8 @@ impl BluetoothScanfilter { } } - pub fn get_name(&self) -> &str { - &self.name + pub fn get_name(&self) -> Option<&str> { + self.name.as_ref().map(|s| s.as_str()) } pub fn get_name_prefix(&self) -> &str { @@ -69,12 +69,12 @@ impl BluetoothScanfilter { } pub fn is_empty_or_invalid(&self) -> bool { - (self.name.is_empty() && + (self.name.is_none() && self.name_prefix.is_empty() && self.get_services().is_empty() && self.manufacturer_id.is_none() && self.service_data_uuid.is_empty()) || - self.name.len() > MAX_NAME_LENGTH || + self.get_name().unwrap_or("").len() > MAX_NAME_LENGTH || self.name_prefix.len() > MAX_NAME_LENGTH } } diff --git a/components/script/dom/bluetooth.rs b/components/script/dom/bluetooth.rs index 10809a4fd5d..144cf03a4be 100644 --- a/components/script/dom/bluetooth.rs +++ b/components/script/dom/bluetooth.rs @@ -217,9 +217,9 @@ fn canonicalize_filter(filter: &BluetoothRequestDeviceFilter) -> Fallible String::new(), + None => None, }; // Step 2.4.5. diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/requestDevice/name-empty-device-from-name-empty-filter.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/requestDevice/name-empty-device-from-name-empty-filter.html.ini deleted file mode 100644 index 1abfe05362f..00000000000 --- a/tests/wpt/mozilla/meta/mozilla/bluetooth/requestDevice/name-empty-device-from-name-empty-filter.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[name-empty-device-from-name-empty-filter.html] - type: testharness - [An empty name device can be obtained by empty name filter.] - expected: FAIL diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/requestDevice/name-empty-filter.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/requestDevice/name-empty-filter.html.ini deleted file mode 100644 index 9d60059908f..00000000000 --- a/tests/wpt/mozilla/meta/mozilla/bluetooth/requestDevice/name-empty-filter.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[name-empty-filter.html] - type: testharness - [A named device is not matched by a filter with an empty name.] - expected: FAIL diff --git a/tests/wpt/mozilla/meta/mozilla/bluetooth/requestDevice/name-missing-device-from-name-empty-filter.html.ini b/tests/wpt/mozilla/meta/mozilla/bluetooth/requestDevice/name-missing-device-from-name-empty-filter.html.ini deleted file mode 100644 index 7737a256495..00000000000 --- a/tests/wpt/mozilla/meta/mozilla/bluetooth/requestDevice/name-missing-device-from-name-empty-filter.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[name-missing-device-from-name-empty-filter.html] - type: testharness - [An unnamed device can not be obtained by empty name filter.] - expected: FAIL