-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Web Bluetooth] Add
manufacturerData
filter when requesting device
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
1 parent
a9efdee
commit 2daa026
Showing
7 changed files
with
290 additions
and
17 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
bluetooth/requestDevice/canonicalizeFilter/data-prefix-and-mask-size.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
38 changes: 38 additions & 0 deletions
38
bluetooth/requestDevice/canonicalizeFilter/empty-manufacturerData-member.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
25 changes: 25 additions & 0 deletions
25
bluetooth/requestDevice/canonicalizeFilter/same-company-identifier.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
bluetooth/requestDevice/manufacturer-data-filter-matches.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.