-
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
2058465
commit a2de699
Showing
10 changed files
with
393 additions
and
20 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
bluetooth/requestDevice/canonicalizeFilter/data-prefix-and-mask-size.https.window.js
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,24 @@ | ||
// META: script=/resources/testharness.js | ||
// META: script=/resources/testharnessreport.js | ||
// META: script=/resources/testdriver.js | ||
// META: script=/resources/testdriver-vendor.js | ||
// META: script=/bluetooth/resources/bluetooth-test.js | ||
// META: script=/bluetooth/resources/bluetooth-fake-devices.js | ||
'use strict'; | ||
const test_desc = | ||
'Manufacturer data mask size must be equal to dataPrefix size.'; | ||
|
||
bluetooth_test(async (t) => { | ||
const companyIdentifier = 0x0001; | ||
const dataPrefix = new Uint8Array([0x01, 0x02, 0x03, 0x04]); | ||
const mask = new Uint8Array([0xff]); | ||
|
||
await promise_rejects_js( | ||
t, TypeError, | ||
requestDeviceWithTrustedClick( | ||
{filters: [{manufacturerData: [{companyIdentifier, mask}]}]})); | ||
await promise_rejects_js( | ||
t, TypeError, requestDeviceWithTrustedClick({ | ||
filters: [{manufacturerData: [{companyIdentifier, dataPrefix, mask}]}] | ||
})); | ||
}, test_desc); |
33 changes: 33 additions & 0 deletions
33
bluetooth/requestDevice/canonicalizeFilter/dataPrefix-buffer-is-detached.https.window.js
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,33 @@ | ||
// META: script=/resources/testdriver.js | ||
// META: script=/resources/testdriver-vendor.js | ||
// META: script=/bluetooth/resources/bluetooth-test.js | ||
// META: script=/bluetooth/resources/bluetooth-fake-devices.js | ||
'use strict'; | ||
const test_desc = 'dataPrefix value buffer must not be detached'; | ||
|
||
function detachBuffer(buffer) { | ||
window.postMessage('', '*', [buffer]); | ||
} | ||
|
||
bluetooth_test(async (t) => { | ||
const companyIdentifier = 0x0001; | ||
|
||
const typed_array = Uint8Array.of(1, 2); | ||
detachBuffer(typed_array.buffer); | ||
|
||
await promise_rejects_dom( | ||
t, 'InvalidStateError', requestDeviceWithTrustedClick({ | ||
filters: | ||
[{manufacturerData: [{companyIdentifier, dataPrefix: typed_array}]}] | ||
})); | ||
|
||
const array_buffer = Uint8Array.of(3, 4).buffer; | ||
detachBuffer(array_buffer); | ||
|
||
await promise_rejects_dom( | ||
t, 'InvalidStateError', requestDeviceWithTrustedClick({ | ||
filters: [ | ||
{manufacturerData: [{companyIdentifier, dataPrefix: array_buffer}]} | ||
] | ||
})); | ||
}, test_desc); |
37 changes: 37 additions & 0 deletions
37
bluetooth/requestDevice/canonicalizeFilter/empty-manufacturerData-member.https.window.js
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,37 @@ | ||
// META: script=/resources/testharness.js | ||
// META: script=/resources/testharnessreport.js | ||
// META: script=/resources/testdriver.js | ||
// META: script=/resources/testdriver-vendor.js | ||
// META: script=/bluetooth/resources/bluetooth-test.js | ||
// META: script=/bluetooth/resources/bluetooth-fake-devices.js | ||
'use strict'; | ||
const test_desc = 'requestDevice with empty manufacturerData. ' + | ||
'Should reject with 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((t) => { | ||
let test_promises = Promise.resolve(); | ||
test_specs.forEach(args => { | ||
test_promises = test_promises.then( | ||
() => promise_rejects_js( | ||
t, TypeError, requestDeviceWithTrustedClick(args))); | ||
}); | ||
return test_promises; | ||
}, test_desc); |
17 changes: 17 additions & 0 deletions
17
bluetooth/requestDevice/canonicalizeFilter/invalid-companyIdentifier.https.window.js
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,17 @@ | ||
// META: script=/resources/testdriver.js | ||
// META: script=/resources/testdriver-vendor.js | ||
// META: script=/bluetooth/resources/bluetooth-test.js | ||
// META: script=/bluetooth/resources/bluetooth-fake-devices.js | ||
'use strict'; | ||
const test_desc = 'companyIdentifier must be in the [0, 65535] range'; | ||
|
||
bluetooth_test(async (t) => { | ||
await promise_rejects_js( | ||
t, TypeError, | ||
requestDeviceWithTrustedClick( | ||
{filters: [{manufacturerData: [{companyIdentifier: -1}]}]})); | ||
await promise_rejects_js( | ||
t, TypeError, | ||
requestDeviceWithTrustedClick( | ||
{filters: [{manufacturerData: [{companyIdentifier: 65536}]}]})); | ||
}, test_desc); |
36 changes: 36 additions & 0 deletions
36
bluetooth/requestDevice/canonicalizeFilter/mask-buffer-is-detached.https.window.js
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,36 @@ | ||
// META: script=/resources/testdriver.js | ||
// META: script=/resources/testdriver-vendor.js | ||
// META: script=/bluetooth/resources/bluetooth-test.js | ||
// META: script=/bluetooth/resources/bluetooth-fake-devices.js | ||
'use strict'; | ||
const test_desc = 'mask value buffer must not be detached'; | ||
|
||
function detachBuffer(buffer) { | ||
window.postMessage('', '*', [buffer]); | ||
} | ||
|
||
bluetooth_test(async (t) => { | ||
const companyIdentifier = 0x0001; | ||
const dataPrefix = Uint8Array.of(1, 2); | ||
|
||
const typed_array = Uint8Array.of(1, 2); | ||
detachBuffer(typed_array.buffer); | ||
|
||
await promise_rejects_dom( | ||
t, 'InvalidStateError', requestDeviceWithTrustedClick({ | ||
filters: [{ | ||
manufacturerData: [{companyIdentifier, dataPrefix, mask: typed_array}] | ||
}] | ||
})); | ||
|
||
const array_buffer = Uint8Array.of(3, 4).buffer; | ||
detachBuffer(array_buffer); | ||
|
||
await promise_rejects_dom( | ||
t, 'InvalidStateError', requestDeviceWithTrustedClick({ | ||
filters: [{ | ||
manufacturerData: | ||
[{companyIdentifier, dataPrefix, mask: array_buffer}] | ||
}] | ||
})); | ||
}, test_desc); |
25 changes: 25 additions & 0 deletions
25
bluetooth/requestDevice/canonicalizeFilter/same-company-identifier.https.window.js
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 @@ | ||
// META: script=/resources/testharness.js | ||
// META: script=/resources/testharnessreport.js | ||
// META: script=/resources/testdriver.js | ||
// META: script=/resources/testdriver-vendor.js | ||
// META: script=/bluetooth/resources/bluetooth-test.js | ||
// META: script=/bluetooth/resources/bluetooth-fake-devices.js | ||
'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( | ||
(t) => promise_rejects_js( | ||
t, TypeError, requestDeviceWithTrustedClick({filters})), | ||
test_desc); |
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
141 changes: 141 additions & 0 deletions
141
bluetooth/requestDevice/manufacturer-data-filter-matches.https.window.js
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,141 @@ | ||
// META: script=/resources/testharness.js | ||
// META: script=/resources/testharnessreport.js | ||
// META: script=/resources/testdriver.js | ||
// META: script=/resources/testdriver-vendor.js | ||
// META: script=/bluetooth/resources/bluetooth-test.js | ||
// META: script=/bluetooth/resources/bluetooth-fake-devices.js | ||
'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, 0x01]), | ||
}], | ||
}], | ||
}, | ||
{ | ||
filters: [{ | ||
manufacturerData: [ | ||
{ | ||
companyIdentifier: 0x0001, | ||
dataPrefix: new Uint8Array([0x01, 0x02]), | ||
mask: new Uint8Array([0xff, 0x01]), | ||
}, | ||
{ | ||
companyIdentifier: 0x0002, | ||
} | ||
], | ||
}], | ||
}, | ||
{ | ||
filters: [{ | ||
manufacturerData: [ | ||
{ | ||
companyIdentifier: 0x0001, | ||
dataPrefix: new Uint8Array([0x01, 0x02]), | ||
mask: new Uint8Array([0xff, 0x01]), | ||
}, | ||
{ | ||
companyIdentifier: 0x0002, | ||
dataPrefix: new Uint8Array([0x03]), | ||
} | ||
], | ||
}], | ||
}, | ||
{ | ||
filters: [{ | ||
manufacturerData: [ | ||
{ | ||
companyIdentifier: 0x0001, | ||
dataPrefix: new Uint8Array([0x01, 0x02]), | ||
mask: new Uint8Array([0xff, 0x01]), | ||
}, | ||
{ | ||
companyIdentifier: 0x0002, | ||
dataPrefix: new Uint8Array([0x03]), | ||
mask: new Uint8Array([0xff]), | ||
} | ||
], | ||
}], | ||
}, | ||
{ | ||
filters: [{ | ||
manufacturerData: [ | ||
{ | ||
companyIdentifier: 0x0001, | ||
dataPrefix: new Uint8Array([0x01, 0x02]), | ||
mask: new Uint8Array([0xff, 0x01]), | ||
}, | ||
{ | ||
companyIdentifier: 0x0002, | ||
dataPrefix: new Uint8Array([0x03, 0x04]), | ||
} | ||
], | ||
}], | ||
}, | ||
{ | ||
filters: [{ | ||
manufacturerData: [ | ||
{ | ||
companyIdentifier: 0x0001, | ||
dataPrefix: new Uint8Array([0x01, 0x02]), | ||
mask: new Uint8Array([0xff, 0x01]), | ||
}, | ||
{ | ||
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(async () => { | ||
const device = await requestDeviceWithTrustedClick(args); | ||
assert_equals(device.name, 'Health Thermometer'); | ||
}); | ||
}); | ||
return test_promises; | ||
}), | ||
test_desc); |
Oops, something went wrong.