Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bluetooth: Migrate generated server tests
This change migrates the scripts to generate GATT server tests and the generated tests themselves to wpt/. BUG=509038 Change-Id: Ie9fbc6442f232b61091cd2f83c832974450936e8 Reviewed-on: https://chromium-review.googlesource.com/843065 Commit-Queue: Ovidio Henriquez <odejesush@chromium.org> Reviewed-by: Conley Owens <cco3@chromium.org> Reviewed-by: Reilly Grant <reillyg@chromium.org> Cr-Commit-Position: refs/heads/master@{#529857}
- Loading branch information
1 parent
9e00941
commit d9fef5c
Showing
58 changed files
with
1,694 additions
and
0 deletions.
There are no files selected for viewing
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,22 @@ | ||
'use strict'; | ||
const test_desc = 'disconnect() called before FUNCTION_NAME. ' + | ||
'Reject with NetworkError.'; | ||
const expected = new DOMException( | ||
'GATT Server is disconnected. Cannot retrieve services. (Re)connect ' + | ||
'first with `device.gatt.connect`.', | ||
'NetworkError'); | ||
let device; | ||
|
||
bluetooth_test(() => getHealthThermometerDevice({ | ||
filters: [{services: ['health_thermometer']}], | ||
optionalServices: ['generic_access'] | ||
}) | ||
.then(_ => ({device} = _)) | ||
.then(() => device.gatt.disconnect()) | ||
.then(() => assert_promise_rejects_with_message( | ||
device.gatt.CALLS([ | ||
getPrimaryService('health_thermometer')| | ||
getPrimaryServices()| | ||
getPrimaryServices('health_thermometer')[UUID]]), | ||
expected)), | ||
test_desc); |
22 changes: 22 additions & 0 deletions
22
bluetooth/script-tests/server/disconnect-called-during-error.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,22 @@ | ||
'use strict'; | ||
const test_desc = 'disconnect() called during a FUNCTION_NAME ' + | ||
'call that fails. Reject with NetworkError.'; | ||
const expected = new DOMException( | ||
'GATT Server is disconnected. Cannot retrieve services. (Re)connect ' + | ||
'first with `device.gatt.connect`.', 'NetworkError'); | ||
let device; | ||
|
||
bluetooth_test(() => getEmptyHealthThermometerDevice() | ||
.then(_ => ({device} = _)) | ||
.then(() => { | ||
let promise = assert_promise_rejects_with_message( | ||
device.gatt.CALLS([ | ||
getPrimaryService('health_thermometer')| | ||
getPrimaryServices()| | ||
getPrimaryServices('health_thermometer')[UUID] | ||
]), | ||
expected) | ||
device.gatt.disconnect(); | ||
return promise; | ||
}), | ||
test_desc); |
23 changes: 23 additions & 0 deletions
23
bluetooth/script-tests/server/disconnect-called-during-success.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,23 @@ | ||
'use strict'; | ||
const test_desc = 'disconnect() called during a FUNCTION_NAME call that ' + | ||
'succeeds. Reject with NetworkError.'; | ||
const expected = new DOMException( | ||
'GATT Server is disconnected. Cannot retrieve services. (Re)connect ' + | ||
'first with `device.gatt.connect`.', | ||
'NetworkError'); | ||
|
||
bluetooth_test(() => getHealthThermometerDevice({ | ||
filters: [{services: ['health_thermometer']}], | ||
optionalServices: ['generic_access'] | ||
}) | ||
.then(({device}) => { | ||
let promise = assert_promise_rejects_with_message( | ||
device.gatt.CALLS([ | ||
getPrimaryService('health_thermometer')| | ||
getPrimaryServices()| | ||
getPrimaryServices('health_thermometer')[UUID] | ||
]), | ||
expected); | ||
device.gatt.disconnect(); | ||
return promise; | ||
}), test_desc); |
39 changes: 39 additions & 0 deletions
39
bluetooth/script-tests/server/disconnect-invalidates-objects.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,39 @@ | ||
'use strict'; | ||
const test_desc = 'Calls on services after we disconnect and connect again. '+ | ||
'Should reject with InvalidStateError.'; | ||
let device, services; | ||
|
||
bluetooth_test(() => getHealthThermometerDevice({ | ||
filters: [{services: ['health_thermometer']}] | ||
}) | ||
.then(_ => ({device} = _)) | ||
.then(() => device.gatt.CALLS([ | ||
getPrimaryService('health_thermometer')| | ||
getPrimaryServices()| | ||
getPrimaryServices('health_thermometer')[UUID]])) | ||
// Convert to array if necessary. | ||
.then(s => services = [].concat(s)) | ||
.then(() => device.gatt.disconnect()) | ||
.then(() => device.gatt.connect()) | ||
.then(() => { | ||
let promises = Promise.resolve(); | ||
for (let service of services) { | ||
let error = new DOMException( | ||
`Service with UUID ${service.uuid} is no longer valid. Remember ` + | ||
`to retrieve the service again after reconnecting.`, | ||
'InvalidStateError'); | ||
promises = promises.then(() => | ||
assert_promise_rejects_with_message( | ||
service.getCharacteristic('measurement_interval'), | ||
error)); | ||
promises = promises.then(() => | ||
assert_promise_rejects_with_message( | ||
service.getCharacteristics(), | ||
error)); | ||
promises = promises.then(() => | ||
assert_promise_rejects_with_message( | ||
service.getCharacteristics('measurement_interval'), | ||
error)); | ||
} | ||
return promises; | ||
}), 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
const test_desc = 'FUNCTION_NAME called before connecting. Reject with ' + | ||
'NetworkError.'; | ||
const expected = new DOMException( | ||
'GATT Server is disconnected. Cannot retrieve services. (Re)connect ' + | ||
'first with `device.gatt.connect`.', | ||
'NetworkError'); | ||
|
||
bluetooth_test(() => getDiscoveredHealthThermometerDevice({ | ||
filters: [{services: ['health_thermometer']}], | ||
optionalServices: ['generic_access'] | ||
}) | ||
.then(({device}) => assert_promise_rejects_with_message( | ||
device.gatt.CALLS([ | ||
getPrimaryService('health_thermometer')| | ||
getPrimaryServices()| | ||
getPrimaryServices('health_thermometer')[UUID] | ||
]), | ||
expected)), | ||
test_desc); |
25 changes: 25 additions & 0 deletions
25
bluetooth/script-tests/server/discovery-complete-no-permission-absent-service.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 @@ | ||
'use strict'; | ||
const test_desc = 'Request for absent service without permission. Should ' + | ||
'Reject with SecurityError even if services have been discovered already.'; | ||
const expected = new DOMException( | ||
'Origin is not allowed to access the service. Tip: Add the service ' + | ||
'UUID to \'optionalServices\' in requestDevice() options. ' + | ||
'https://goo.gl/HxfxSQ', | ||
'SecurityError'); | ||
let device; | ||
|
||
bluetooth_test(() => getHealthThermometerDeviceWithServicesDiscovered({ | ||
filters: [{services: ['health_thermometer']}] | ||
}) | ||
.then(_ => ({device} = _)) | ||
.then(() => Promise.all([ | ||
assert_promise_rejects_with_message( | ||
device.gatt.CALLS([ | ||
getPrimaryService(glucose.alias)| | ||
getPrimaryServices(glucose.alias)[UUID] | ||
]), expected), | ||
assert_promise_rejects_with_message( | ||
device.gatt.FUNCTION_NAME(glucose.name), expected), | ||
assert_promise_rejects_with_message( | ||
device.gatt.FUNCTION_NAME(glucose.uuid), expected)])), | ||
test_desc); |
16 changes: 16 additions & 0 deletions
16
bluetooth/script-tests/server/discovery-complete-service-not-found.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,16 @@ | ||
'use strict'; | ||
const test_desc = 'Request for absent service. Must reject with ' + | ||
'NotFoundError even when the services have previously been discovered.'; | ||
|
||
bluetooth_test(() => getHealthThermometerDeviceWithServicesDiscovered({ | ||
filters: [{services: ['health_thermometer']}], | ||
optionalServices: ['glucose']}) | ||
.then(({device}) => assert_promise_rejects_with_message( | ||
device.gatt.CALLS([ | ||
getPrimaryService('glucose')| | ||
getPrimaryServices('glucose')[UUID] | ||
]), | ||
new DOMException( | ||
`No Services matching UUID ${glucose.uuid} found in Device.`, | ||
'NotFoundError'))), | ||
test_desc); |
25 changes: 25 additions & 0 deletions
25
bluetooth/script-tests/server/garbage-collection-ran-during-error.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 @@ | ||
'use strict'; | ||
const test_desc = 'Garbage Collection ran during a FUNCTION_NAME ' + | ||
'call that failed. Should not crash.' | ||
const expected = new DOMException( | ||
'GATT Server is disconnected. Cannot retrieve services. (Re)connect first ' + | ||
'with `device.gatt.connect`.', | ||
'NetworkError'); | ||
let promise; | ||
|
||
bluetooth_test(() => getEmptyHealthThermometerDevice() | ||
.then(({device}) => { | ||
promise = assert_promise_rejects_with_message( | ||
device.gatt.CALLS([ | ||
getPrimaryService('health_thermometer')| | ||
getPrimaryServices()| | ||
getPrimaryServices('health_thermometer')[UUID] | ||
]), | ||
expected); | ||
// Disconnect called to clear attributeInstanceMap and allow the | ||
// object to get garbage collected. | ||
device.gatt.disconnect(); | ||
return runGarbageCollection(); | ||
}) | ||
.then(() => promise), | ||
test_desc); |
24 changes: 24 additions & 0 deletions
24
bluetooth/script-tests/server/garbage-collection-ran-during-success.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 @@ | ||
'use strict'; | ||
const test_desc = 'Garbage Collection ran during a FUNCTION_NAME call that ' + | ||
'succeeds. Should not crash.'; | ||
const expected = new DOMException( | ||
'GATT Server is disconnected. Cannot retrieve services. ' + | ||
'(Re)connect first with `device.gatt.connect`.', | ||
'NetworkError'); | ||
let promise; | ||
|
||
bluetooth_test(() => getHealthThermometerDevice({ | ||
filters: [{services: ['health_thermometer']}] | ||
}) | ||
.then(({device}) => { | ||
promise = assert_promise_rejects_with_message( | ||
device.gatt.CALLS([ | ||
getPrimaryService('health_thermometer') | | ||
getPrimaryServices() | | ||
getPrimaryServices('health_thermometer')[UUID]]), | ||
expected); | ||
device.gatt.disconnect(); | ||
return runGarbageCollection(); | ||
}) | ||
.then(() => promise), | ||
test_desc); |
35 changes: 35 additions & 0 deletions
35
bluetooth/script-tests/server/get-different-service-after-reconnection.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,35 @@ | ||
'use strict'; | ||
const test_desc = 'Calls to FUNCTION_NAME after a disconnection should return ' + | ||
'a different object.'; | ||
let device, services_first_connection, services_second_connection; | ||
|
||
bluetooth_test(() => getHealthThermometerDevice({ | ||
filters: [{services: ['health_thermometer']}], | ||
optionalServices: ['generic_access'] | ||
}) | ||
.then(_ => ({device} = _)) | ||
.then(() => device.gatt.CALLS([ | ||
getPrimaryService('health_thermometer')| | ||
getPrimaryServices()| | ||
getPrimaryServices('health_thermometer')[UUID]])) | ||
.then(services => services_first_connection = services) | ||
.then(() => device.gatt.disconnect()) | ||
.then(() => device.gatt.connect()) | ||
.then(() => device.gatt.PREVIOUS_CALL) | ||
.then(services => services_second_connection = services) | ||
.then(() => { | ||
// Convert to arrays if necessary. | ||
services_first_connection = [].concat(services_first_connection); | ||
services_second_connection = [].concat(services_second_connection); | ||
|
||
assert_equals(services_first_connection.length, | ||
services_second_connection.length); | ||
|
||
let first_connection_set = new Set(services_first_connection); | ||
let second_connection_set = new Set(services_second_connection); | ||
|
||
// The two sets should be disjoint. | ||
let common_services = services_first_connection.filter( | ||
val => second_connection_set.has(val)); | ||
assert_equals(common_services.length, 0); | ||
}), 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
const test_desc = 'Calls to FUNCTION_NAME should return the same object.'; | ||
let device; | ||
|
||
bluetooth_test(() => getHealthThermometerDevice({ | ||
filters: [{services: ['health_thermometer']}], | ||
optionalServices: ['generic_access']}) | ||
.then(({device}) => Promise.all([ | ||
device.gatt.CALLS([ | ||
getPrimaryService('health_thermometer')| | ||
getPrimaryServices()| | ||
getPrimaryServices('health_thermometer')[UUID]]), | ||
device.gatt.PREVIOUS_CALL])) | ||
.then(([services_first_call, services_second_call]) => { | ||
// Convert to arrays if necessary. | ||
services_first_call = [].concat(services_first_call); | ||
services_second_call = [].concat(services_second_call); | ||
|
||
assert_equals(services_first_call.length, services_second_call.length); | ||
|
||
let first_call_set = new Set(services_first_call); | ||
assert_equals(services_first_call.length, first_call_set.size); | ||
let second_call_set = new Set(services_second_call); | ||
assert_equals(services_second_call.length, second_call_set.size); | ||
|
||
services_first_call.forEach(service => { | ||
assert_true(second_call_set.has(service)) | ||
}); | ||
|
||
services_second_call.forEach(service => { | ||
assert_true(first_call_set.has(service)); | ||
}); | ||
}), 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
const test_desc = 'Wrong Service name. Reject with TypeError.'; | ||
const expected = new DOMException( | ||
"Failed to execute 'FUNCTION_NAME' on " + | ||
"'BluetoothRemoteGATTServer': Invalid Service name: " + | ||
"'wrong_name'. It must be a valid UUID alias (e.g. 0x1234), " + | ||
"UUID (lowercase hex characters e.g. " + | ||
"'00001234-0000-1000-8000-00805f9b34fb'), " + | ||
"or recognized standard name from " + | ||
"https://www.bluetooth.com/specifications/gatt/services" + | ||
" e.g. 'alert_notification'.", | ||
'TypeError'); | ||
|
||
bluetooth_test(() => getHealthThermometerDevice() | ||
.then(({device}) => assert_promise_rejects_with_message( | ||
device.gatt.CALLS([ | ||
getPrimaryService('wrong_name')| | ||
getPrimaryServices('wrong_name') | ||
]), | ||
expected, | ||
'Wrong Service name passed.')), | ||
test_desc); |
23 changes: 23 additions & 0 deletions
23
bluetooth/script-tests/server/no-permission-absent-service.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,23 @@ | ||
'use strict'; | ||
const test_desc = 'Request for absent service without permission. ' + | ||
'Reject with SecurityError.'; | ||
const expected = new DOMException( | ||
'Origin is not allowed to access the service. Tip: Add the service UUID ' + | ||
'to \'optionalServices\' in requestDevice() options. ' + | ||
'https://goo.gl/HxfxSQ', | ||
'SecurityError'); | ||
|
||
bluetooth_test(() => getHealthThermometerDevice({ | ||
filters: [{services: ['health_thermometer']}] | ||
}) | ||
.then(({device}) => Promise.all([ | ||
assert_promise_rejects_with_message( | ||
device.gatt.CALLS([ | ||
getPrimaryService(glucose.alias)| | ||
getPrimaryServices(glucose.alias)[UUID] | ||
]), expected), | ||
assert_promise_rejects_with_message( | ||
device.gatt.FUNCTION_NAME(glucose.name), expected), | ||
assert_promise_rejects_with_message( | ||
device.gatt.FUNCTION_NAME(glucose.uuid), expected)])), | ||
test_desc); |
17 changes: 17 additions & 0 deletions
17
bluetooth/script-tests/server/no-permission-for-any-service.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 @@ | ||
'use strict'; | ||
const test_desc = 'Request for present service without permission to access ' + | ||
'any service. Reject with SecurityError.'; | ||
const expected = new DOMException( | ||
'Origin is not allowed to access any service. Tip: Add the service ' + | ||
'UUID to \'optionalServices\' in requestDevice() options. ' + | ||
'https://goo.gl/HxfxSQ', | ||
'SecurityError'); | ||
|
||
bluetooth_test(() => getHealthThermometerDevice({acceptAllDevices: true}) | ||
.then(({device}) => assert_promise_rejects_with_message( | ||
device.gatt.CALLS([ | ||
getPrimaryService('heart_rate')| | ||
getPrimaryServices()| | ||
getPrimaryServices('heart_rate')[UUID]]), | ||
expected)), | ||
test_desc); |
22 changes: 22 additions & 0 deletions
22
bluetooth/script-tests/server/no-permission-present-service.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,22 @@ | ||
'use strict'; | ||
const test_desc = 'Request for present service without permission. ' + | ||
'Reject with SecurityError.'; | ||
const expected = new DOMException( | ||
'Origin is not allowed to access the service. Tip: Add the service UUID ' + | ||
'to \'optionalServices\' in requestDevice() options. https://goo.gl/HxfxSQ', | ||
'SecurityError'); | ||
|
||
bluetooth_test(() => getHealthThermometerDevice({ | ||
filters: [{services: ['health_thermometer']}] | ||
}) | ||
.then(({device}) => Promise.all([ | ||
assert_promise_rejects_with_message( | ||
device.gatt.CALLS([ | ||
getPrimaryService(generic_access.alias)| | ||
getPrimaryServices(generic_access.alias)[UUID] | ||
]), expected), | ||
assert_promise_rejects_with_message( | ||
device.gatt.FUNCTION_NAME(generic_access.name), expected), | ||
assert_promise_rejects_with_message( | ||
device.gatt.FUNCTION_NAME(generic_access.uuid), expected)])), | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
const test_desc = 'Request for absent service. Reject with NotFoundError.'; | ||
|
||
bluetooth_test(() => getHealthThermometerDevice({ | ||
filters: [{services: ['health_thermometer']}], | ||
optionalServices: ['glucose'] | ||
}) | ||
.then(({device}) => assert_promise_rejects_with_message( | ||
device.gatt.CALLS([ | ||
getPrimaryService('glucose')| | ||
getPrimaryServices('glucose')[UUID] | ||
]), | ||
new DOMException( | ||
`No Services matching UUID ${glucose.uuid} found in Device.`, | ||
'NotFoundError'))), | ||
test_desc); |
Oops, something went wrong.