Skip to content

Commit

Permalink
[Web Bluetooth] Add manufacturerData filter when requesting device
Browse files Browse the repository at this point in the history
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
  • Loading branch information
beaufortfrancois authored and chromium-wpt-export-bot committed Apr 27, 2021
1 parent a9efdee commit 2daa026
Show file tree
Hide file tree
Showing 7 changed files with 290 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/bluetooth/resources/bluetooth-test.js"></script>
<script src="/bluetooth/resources/bluetooth-fake-devices.js"></script>
<script>
'use strict';
const test_desc = 'Manufacturer data mask size must be equal to dataPrefix size.';
const expected = new TypeError();

let filters = [{
manufacturerData: [{
companyIdentifier: 0x0001,
dataPrefix: new Uint8Array([0x01, 0x02, 0x03, 0x04]),
mask: new Uint8Array([0xff]),
}],
}];

bluetooth_test(
() => assert_promise_rejects_with_message(
requestDeviceWithTrustedClick({filters}), expected),
test_desc);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/bluetooth/resources/bluetooth-test.js"></script>
<script src="/bluetooth/resources/bluetooth-fake-devices.js"></script>
<script>
'use strict';
const test_desc = 'requestDevice with empty manufacturerData. ' +
'Should reject with TypeError.';
const expected = new TypeError();
const test_specs = [
{filters: [{manufacturerData: []}]}, {filters: [{manufacturerData: [], name: 'Name'}]},
{filters: [{manufacturerData: [], services: ['heart_rate']}]},
{filters: [{manufacturerData: [], name: 'Name', services: ['heart_rate']}]},
{filters: [{manufacturerData: []}], optionalServices: ['heart_rate']},
{filters: [{manufacturerData: [], name: 'Name'}], optionalServices: ['heart_rate']},
{
filters: [{manufacturerData: [], services: ['heart_rate']}],
optionalServices: ['heart_rate']
},
{
filters: [{manufacturerData: [], name: 'Name', services: ['heart_rate']}],
optionalServices: ['heart_rate']
}
];

bluetooth_test(() => {
let test_promises = Promise.resolve();
test_specs.forEach(args => {
test_promises = test_promises.then(
() => assert_promise_rejects_with_message(
requestDeviceWithTrustedClick(args), expected));
});
return test_promises;
}, test_desc);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/bluetooth/resources/bluetooth-test.js"></script>
<script src="/bluetooth/resources/bluetooth-fake-devices.js"></script>
<script>
'use strict';
const test_desc = 'Manufacturer data company identifier must be unique.';
const expected = new TypeError();

let filters = [{
manufacturerData: [{
companyIdentifier: 0x0001,
}, {
companyIdentifier: 0x0001,
}]
}];

bluetooth_test(
() => assert_promise_rejects_with_message(
requestDeviceWithTrustedClick({filters}), expected),
test_desc);
</script>
34 changes: 30 additions & 4 deletions bluetooth/requestDevice/filter-matches.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
let matching_services = [health_thermometer.uuid];
let matching_name = 'Health Thermometer';
let matching_namePrefix = 'Health';
let matching_manufacturerData = [{ companyIdentifier: 0x0001 }];

let test_specs = [
{
Expand All @@ -24,25 +25,50 @@
name: matching_name,
}]
},
{filters: [{services: matching_services, namePrefix: matching_namePrefix}]}, {
{
filters: [{
services: matching_services,
namePrefix: matching_namePrefix
}]
},
{
filters: [{
services: matching_services,
manufacturerData: matching_manufacturerData
}]
},
{
filters: [{
name: matching_name,
}],
optionalServices: matching_services
},
{
filters: [{name: matching_name, namePrefix: matching_namePrefix}],
filters: [{
namePrefix: matching_namePrefix
}],
optionalServices: matching_services
},
{
filters: [{
manufacturerData: matching_manufacturerData
}],
optionalServices: matching_services
},
{
filters: [{namePrefix: matching_namePrefix}],
filters: [{
name: matching_name,
namePrefix: matching_namePrefix,
manufacturerData: matching_manufacturerData
}],
optionalServices: matching_services
},
{
filters: [{
services: matching_services,
name: matching_name,
namePrefix: matching_namePrefix
namePrefix: matching_namePrefix,
manufacturerData: matching_manufacturerData
}]
}
];
Expand Down
130 changes: 130 additions & 0 deletions bluetooth/requestDevice/manufacturer-data-filter-matches.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/bluetooth/resources/bluetooth-test.js"></script>
<script src="/bluetooth/resources/bluetooth-fake-devices.js"></script>
<script>
'use strict';
const test_desc = 'Matches a filter when manufacturer data match.';

let test_specs = [
{
filters: [{
manufacturerData: [{
companyIdentifier: 0x0001,
}],
}],
},
{
filters: [{
manufacturerData: [{
companyIdentifier: 0x0001,
dataPrefix: new Uint8Array([0x01]),
}],
}],
},
{
filters: [{
manufacturerData: [{
companyIdentifier: 0x0001,
dataPrefix: new Uint8Array([0x01]),
mask: new Uint8Array([0xff]),
}],
}],
},
{
filters: [{
manufacturerData: [{
companyIdentifier: 0x0001,
dataPrefix: new Uint8Array([0x01, 0x02]),
}],
}],
},
{
filters: [{
manufacturerData: [{
companyIdentifier: 0x0001,
dataPrefix: new Uint8Array([0x01, 0x02]),
mask: new Uint8Array([0xff, 0xff]),
}],
}],
},
{
filters: [{
manufacturerData: [{
companyIdentifier: 0x0001,
dataPrefix: new Uint8Array([0x01, 0x02]),
mask: new Uint8Array([0xff, 0xff]),
}, {
companyIdentifier: 0x0002,
}],
}],
},
{
filters: [{
manufacturerData: [{
companyIdentifier: 0x0001,
dataPrefix: new Uint8Array([0x01, 0x02]),
mask: new Uint8Array([0xff, 0xff]),
}, {
companyIdentifier: 0x0002,
dataPrefix: new Uint8Array([0x03]),
}],
}],
},
{
filters: [{
manufacturerData: [{
companyIdentifier: 0x0001,
dataPrefix: new Uint8Array([0x01, 0x02]),
mask: new Uint8Array([0xff, 0xff]),
}, {
companyIdentifier: 0x0002,
dataPrefix: new Uint8Array([0x03]),
mask: new Uint8Array([0xff]),
}],
}],
},
{
filters: [{
manufacturerData: [{
companyIdentifier: 0x0001,
dataPrefix: new Uint8Array([0x01, 0x02]),
mask: new Uint8Array([0xff, 0xff]),
}, {
companyIdentifier: 0x0002,
dataPrefix: new Uint8Array([0x03, 0x04]),
}],
}],
},
{
filters: [{
manufacturerData: [{
companyIdentifier: 0x0001,
dataPrefix: new Uint8Array([0x01, 0x02]),
mask: new Uint8Array([0xff, 0xff]),
}, {
companyIdentifier: 0x0002,
dataPrefix: new Uint8Array([0x03, 0x04]),
mask: new Uint8Array([0xff, 0xff])
}],
}],
},
];

bluetooth_test(
() => setUpHealthThermometerDevice().then(() => {
let test_promises = Promise.resolve();
test_specs.forEach(args => {
test_promises =
test_promises.then(() => requestDeviceWithTrustedClick(args))
.then(device => {
assert_equals(device.name, 'Health Thermometer');
});
});
return test_promises;
}),
test_desc);
</script>
Loading

0 comments on commit 2daa026

Please sign in to comment.