Commit ae73061c authored by Conley Owens's avatar Conley Owens Committed by Commit Bot

bluetooth: web: test: Use AllResponsesConsumed

This change uses AllResponsesConsumed in the bluetooth Web Platform
Tests in order to make sure we have consumed all the anticipatory
responses that we've set on our fakes.

BUG=569709

Change-Id: I9767792fcd5dda71fabf2f8941638f744aefa2dc
Reviewed-on: https://chromium-review.googlesource.com/988422
Commit-Queue: Conley Owens <cco3@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548125}
parent bc234e0d
...@@ -43,7 +43,11 @@ void FakeBluetooth::SimulateCentral(mojom::CentralState state, ...@@ -43,7 +43,11 @@ void FakeBluetooth::SimulateCentral(mojom::CentralState state,
void FakeBluetooth::AllResponsesConsumed( void FakeBluetooth::AllResponsesConsumed(
AllResponsesConsumedCallback callback) { AllResponsesConsumedCallback callback) {
std::move(callback).Run(fake_central_->AllResponsesConsumed()); if (fake_central_) {
std::move(callback).Run(fake_central_->AllResponsesConsumed());
return;
}
std::move(callback).Run(true);
} }
} // namespace bluetooth } // namespace bluetooth
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
const test_desc = 'A device disconnecting while connected should fire the ' + const test_desc = 'A device disconnecting while connected should fire the ' +
'gattserverdisconnected event.'; 'gattserverdisconnected event.';
bluetooth_test(() => getHealthThermometerDevice() bluetooth_test(() => getConnectedHealthThermometerDevice()
.then(({device, fake_peripheral}) => { .then(({device, fake_peripheral}) => {
fake_peripheral.simulateGATTDisconnection(); fake_peripheral.simulateGATTDisconnection();
return eventPromise(device, 'gattserverdisconnected'); return eventPromise(device, 'gattserverdisconnected');
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
const test_desc = 'A device disconnecting after the BluetoothDevice object ' + const test_desc = 'A device disconnecting after the BluetoothDevice object ' +
'has been GC\'ed should not access freed memory.'; 'has been GC\'ed should not access freed memory.';
bluetooth_test(() => getHealthThermometerDevice() bluetooth_test(() => getConnectedHealthThermometerDevice()
.then(({fake_peripheral}) => { .then(({fake_peripheral}) => {
// 1. Disconnect. // 1. Disconnect.
fake_peripheral.simulateGATTDisconnection(); fake_peripheral.simulateGATTDisconnection();
......
...@@ -12,7 +12,7 @@ const test_desc = 'If a site disconnects from a device while the platform is ' + ...@@ -12,7 +12,7 @@ const test_desc = 'If a site disconnects from a device while the platform is ' +
let device, fake_peripheral; let device, fake_peripheral;
let num_events = 0; let num_events = 0;
bluetooth_test(() => getHealthThermometerDevice() bluetooth_test(() => getConnectedHealthThermometerDevice()
.then(_ => ({device, fake_peripheral} = _)) .then(_ => ({device, fake_peripheral} = _))
// 1. Listen for disconnections. // 1. Listen for disconnections.
.then(() => .then(() =>
......
...@@ -10,7 +10,7 @@ let test_desc = 'A device that reconnects during the gattserverdisconnected ' + ...@@ -10,7 +10,7 @@ let test_desc = 'A device that reconnects during the gattserverdisconnected ' +
'event should still receive gattserverdisconnected events after ' + 'event should still receive gattserverdisconnected events after ' +
're-connection.'; 're-connection.';
let device, fake_peripheral; let device, fake_peripheral;
bluetooth_test(() => getHealthThermometerDevice() bluetooth_test(() => getConnectedHealthThermometerDevice()
.then(_ => ({device, fake_peripheral} = _)) .then(_ => ({device, fake_peripheral} = _))
// 1. Disconnect. // 1. Disconnect.
.then(() => new Promise(resolve => { .then(() => new Promise(resolve => {
......
...@@ -17,7 +17,7 @@ test(() => { ...@@ -17,7 +17,7 @@ test(() => {
const test_desc_attr = 'BluetoothDevice attributes.'; const test_desc_attr = 'BluetoothDevice attributes.';
let device; let device;
bluetooth_test(() => getHealthThermometerDevice() bluetooth_test(() => getConnectedHealthThermometerDevice()
.then(({device}) => { .then(({device}) => {
assert_equals(device.constructor.name, 'BluetoothDevice'); assert_equals(device.constructor.name, 'BluetoothDevice');
var old_device_id = device.id; var old_device_id = device.id;
......
...@@ -14,7 +14,7 @@ const expected = new DOMException( ...@@ -14,7 +14,7 @@ const expected = new DOMException(
'requestDevice() options. https://goo.gl/HxfxSQ', 'requestDevice() options. https://goo.gl/HxfxSQ',
'SecurityError'); 'SecurityError');
bluetooth_test(() => getHealthThermometerDevice({acceptAllDevices: true}) bluetooth_test(() => getConnectedHealthThermometerDevice({acceptAllDevices: true})
.then(({device}) => assert_promise_rejects_with_message( .then(({device}) => assert_promise_rejects_with_message(
device.gatt.getPrimaryServices(), device.gatt.getPrimaryServices(),
expected)), expected)),
......
...@@ -22,8 +22,6 @@ bluetooth_test(() => getDiscoveredHealthThermometerDevice({ ...@@ -22,8 +22,6 @@ bluetooth_test(() => getDiscoveredHealthThermometerDevice({
.then(() => .then(() =>
fake_peripheral.setNextGATTConnectionResponse({code: HCI_SUCCESS})) fake_peripheral.setNextGATTConnectionResponse({code: HCI_SUCCESS}))
.then(() => device.gatt.connect()) .then(() => device.gatt.connect())
.then(() =>
fake_peripheral.setNextGATTDiscoveryResponse({code: HCI_SUCCESS}))
.then(() => Promise.all([ .then(() => Promise.all([
assert_promise_rejects_with_message( assert_promise_rejects_with_message(
device.gatt.getPrimaryService('human_interface_device'), device.gatt.getPrimaryService('human_interface_device'),
......
...@@ -13,7 +13,7 @@ const cross_origin_src = 'https://{{domains[www]}}:{{ports[https][0]}}' + ...@@ -13,7 +13,7 @@ const cross_origin_src = 'https://{{domains[www]}}:{{ports[https][0]}}' +
'/bluetooth/resources/health-thermometer-iframe.html' '/bluetooth/resources/health-thermometer-iframe.html'
let iframe = document.createElement('iframe'); let iframe = document.createElement('iframe');
bluetooth_test(() => setUpConnectableHealthThermometerDevice() bluetooth_test(() => setUpHealthThermometerDevice()
// 1. Load the iframe. // 1. Load the iframe.
.then(() => new Promise(resolve => { .then(() => new Promise(resolve => {
iframe.src = cross_origin_src; iframe.src = cross_origin_src;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
'use strict'; 'use strict';
const test_desc = 'Discover a device using alias, name, or UUID.'; const test_desc = 'Discover a device using alias, name, or UUID.';
bluetooth_test(() => getHealthThermometerDevice() bluetooth_test(() => getConnectedHealthThermometerDevice()
// Chrome will always close the previous chooser in the process of handling // Chrome will always close the previous chooser in the process of handling
// a user gesture for the next request, so these need to be done // a user gesture for the next request, so these need to be done
// sequentially. // sequentially.
......
...@@ -14,7 +14,7 @@ const expected = 'SecurityError: requestDevice() called from cross-origin ' + ...@@ -14,7 +14,7 @@ const expected = 'SecurityError: requestDevice() called from cross-origin ' +
let iframe = document.createElement('iframe'); let iframe = document.createElement('iframe');
bluetooth_test(() => getHealthThermometerDevice() bluetooth_test(() => getConnectedHealthThermometerDevice()
// 1. Load the iframe. // 1. Load the iframe.
.then(() => new Promise(resolve => { .then(() => new Promise(resolve => {
iframe.sandbox.add('allow-scripts'); iframe.sandbox.add('allow-scripts');
......
...@@ -66,7 +66,9 @@ function bluetooth_test(func, name, properties) { ...@@ -66,7 +66,9 @@ function bluetooth_test(func, name, properties) {
.then(() => promise_test(t => Promise.resolve() .then(() => promise_test(t => Promise.resolve()
// Trigger Chromium-specific setup. // Trigger Chromium-specific setup.
.then(performChromiumSetup) .then(performChromiumSetup)
.then(() => func(t)), name, properties)); .then(() => func(t))
.then(() => navigator.bluetooth.test.allResponsesConsumed())
.then(consumed => assert_true(consumed)), name, properties));
} }
// HCI Error Codes. Used for simulateGATT[Dis]ConnectionResponse. // HCI Error Codes. Used for simulateGATT[Dis]ConnectionResponse.
...@@ -926,42 +928,53 @@ function getEmptyHealthThermometerService(options) { ...@@ -926,42 +928,53 @@ function getEmptyHealthThermometerService(options) {
// The primary service with 'device_information' UUID has a characteristics // The primary service with 'device_information' UUID has a characteristics
// with UUID 'serial_number_string'. The device has been connected to and its // with UUID 'serial_number_string'. The device has been connected to and its
// attributes are ready to be discovered. // attributes are ready to be discovered.
// TODO(crbug.com/719816): Add descriptors.
function getHIDDevice(options) { function getHIDDevice(options) {
let device, fake_peripheral;
return getConnectedHIDDevice(options)
.then(_ => ({device, fake_peripheral} = _))
.then(() => fake_peripheral.setNextGATTDiscoveryResponse({
code: HCI_SUCCESS,
}))
.then(() => ({device, fake_peripheral}));
}
// Similar to getHealthThermometerDevice except the GATT discovery
// response has not been set yet so more attributes can still be added.
// TODO(crbug.com/719816): Add descriptors.
function getConnectedHIDDevice(options) {
let device, fake_peripheral;
return setUpPreconnectedDevice({ return setUpPreconnectedDevice({
address: '10:10:10:10:10:10', address: '10:10:10:10:10:10',
name: 'HID Device', name: 'HID Device',
knownServiceUUIDs: [ knownServiceUUIDs: [
'generic_access', 'generic_access',
'device_information', 'device_information',
'human_interface_device' 'human_interface_device',
], ],
}) })
.then(fake_peripheral => { .then(_ => (fake_peripheral = _))
return requestDeviceWithTrustedClick(options) .then(() => requestDeviceWithTrustedClick(options))
.then(device => { .then(_ => (device = _))
return fake_peripheral .then(() => fake_peripheral.setNextGATTConnectionResponse({
.setNextGATTConnectionResponse({ code: HCI_SUCCESS,
code: HCI_SUCCESS}) }))
.then(() => device.gatt.connect()) .then(() => device.gatt.connect())
.then(() => fake_peripheral.addFakeService({ .then(() => fake_peripheral.addFakeService({
uuid: 'generic_access'})) uuid: 'generic_access',
.then(() => fake_peripheral.addFakeService({ }))
uuid: 'device_information'})) .then(() => fake_peripheral.addFakeService({
// Blocklisted Characteristic: uuid: 'device_information',
// https://github.com/WebBluetoothCG/registries/blob/master/gatt_blocklist.txt }))
.then(dev_info => dev_info.addFakeCharacteristic({ // Blocklisted Characteristic:
uuid: 'serial_number_string', properties: ['read']})) // https://github.com/WebBluetoothCG/registries/blob/master/gatt_blocklist.txt
.then(() => fake_peripheral.addFakeService({ .then(dev_info => dev_info.addFakeCharacteristic({
uuid: 'human_interface_device'})) uuid: 'serial_number_string',
.then(() => fake_peripheral.setNextGATTDiscoveryResponse({ properties: ['read'],
code: HCI_SUCCESS})) }))
.then(() => ({ .then(() => fake_peripheral.addFakeService({
device: device, uuid: 'human_interface_device',
fake_peripheral: fake_peripheral }))
})); .then(() => ({device, fake_peripheral}));
});
});
} }
// Similar to getHealthThermometerDevice() except the device // Similar to getHealthThermometerDevice() except the device
......
...@@ -7,7 +7,7 @@ const expected = new DOMException( ...@@ -7,7 +7,7 @@ const expected = new DOMException(
'NetworkError'); 'NetworkError');
let device; let device;
bluetooth_test(() => getHealthThermometerDevice({ bluetooth_test(() => getConnectedHealthThermometerDevice({
filters: [{services: ['health_thermometer']}], filters: [{services: ['health_thermometer']}],
optionalServices: ['generic_access'] optionalServices: ['generic_access']
}) })
......
...@@ -11,7 +11,7 @@ const expected = new DOMException( ...@@ -11,7 +11,7 @@ const expected = new DOMException(
" e.g. 'alert_notification'.", " e.g. 'alert_notification'.",
'TypeError'); 'TypeError');
bluetooth_test(() => getHealthThermometerDevice() bluetooth_test(() => getConnectedHealthThermometerDevice()
.then(({device}) => assert_promise_rejects_with_message( .then(({device}) => assert_promise_rejects_with_message(
device.gatt.CALLS([ device.gatt.CALLS([
getPrimaryService('wrong_name')| getPrimaryService('wrong_name')|
......
...@@ -7,7 +7,7 @@ const expected = new DOMException( ...@@ -7,7 +7,7 @@ const expected = new DOMException(
'https://goo.gl/HxfxSQ', 'https://goo.gl/HxfxSQ',
'SecurityError'); 'SecurityError');
bluetooth_test(() => getHealthThermometerDevice({ bluetooth_test(() => getConnectedHealthThermometerDevice({
filters: [{services: ['health_thermometer']}] filters: [{services: ['health_thermometer']}]
}) })
.then(({device}) => Promise.all([ .then(({device}) => Promise.all([
......
...@@ -7,7 +7,7 @@ const expected = new DOMException( ...@@ -7,7 +7,7 @@ const expected = new DOMException(
'https://goo.gl/HxfxSQ', 'https://goo.gl/HxfxSQ',
'SecurityError'); 'SecurityError');
bluetooth_test(() => getHealthThermometerDevice({acceptAllDevices: true}) bluetooth_test(() => getConnectedHealthThermometerDevice({acceptAllDevices: true})
.then(({device}) => assert_promise_rejects_with_message( .then(({device}) => assert_promise_rejects_with_message(
device.gatt.CALLS([ device.gatt.CALLS([
getPrimaryService('heart_rate')| getPrimaryService('heart_rate')|
......
...@@ -6,7 +6,7 @@ const expected = new DOMException( ...@@ -6,7 +6,7 @@ const expected = new DOMException(
'to \'optionalServices\' in requestDevice() options. https://goo.gl/HxfxSQ', 'to \'optionalServices\' in requestDevice() options. https://goo.gl/HxfxSQ',
'SecurityError'); 'SecurityError');
bluetooth_test(() => getHealthThermometerDevice({ bluetooth_test(() => getConnectedHealthThermometerDevice({
filters: [{services: ['health_thermometer']}] filters: [{services: ['health_thermometer']}]
}) })
.then(({device}) => Promise.all([ .then(({device}) => Promise.all([
......
...@@ -15,7 +15,7 @@ const expected = new DOMException( ...@@ -15,7 +15,7 @@ const expected = new DOMException(
'NetworkError'); 'NetworkError');
let device; let device;
bluetooth_test(() => getHealthThermometerDevice({ bluetooth_test(() => getConnectedHealthThermometerDevice({
filters: [{services: ['health_thermometer']}], filters: [{services: ['health_thermometer']}],
optionalServices: ['generic_access'] optionalServices: ['generic_access']
}) })
......
...@@ -19,7 +19,7 @@ const expected = new DOMException( ...@@ -19,7 +19,7 @@ const expected = new DOMException(
" e.g. 'alert_notification'.", " e.g. 'alert_notification'.",
'TypeError'); 'TypeError');
bluetooth_test(() => getHealthThermometerDevice() bluetooth_test(() => getConnectedHealthThermometerDevice()
.then(({device}) => assert_promise_rejects_with_message( .then(({device}) => assert_promise_rejects_with_message(
device.gatt.getPrimaryService('wrong_name'), device.gatt.getPrimaryService('wrong_name'),
expected, expected,
......
...@@ -15,7 +15,7 @@ const expected = new DOMException( ...@@ -15,7 +15,7 @@ const expected = new DOMException(
'https://goo.gl/HxfxSQ', 'https://goo.gl/HxfxSQ',
'SecurityError'); 'SecurityError');
bluetooth_test(() => getHealthThermometerDevice({ bluetooth_test(() => getConnectedHealthThermometerDevice({
filters: [{services: ['health_thermometer']}] filters: [{services: ['health_thermometer']}]
}) })
.then(({device}) => Promise.all([ .then(({device}) => Promise.all([
......
...@@ -15,7 +15,7 @@ const expected = new DOMException( ...@@ -15,7 +15,7 @@ const expected = new DOMException(
'https://goo.gl/HxfxSQ', 'https://goo.gl/HxfxSQ',
'SecurityError'); 'SecurityError');
bluetooth_test(() => getHealthThermometerDevice({acceptAllDevices: true}) bluetooth_test(() => getConnectedHealthThermometerDevice({acceptAllDevices: true})
.then(({device}) => assert_promise_rejects_with_message( .then(({device}) => assert_promise_rejects_with_message(
device.gatt.getPrimaryService('heart_rate'), device.gatt.getPrimaryService('heart_rate'),
expected)), expected)),
......
...@@ -14,7 +14,7 @@ const expected = new DOMException( ...@@ -14,7 +14,7 @@ const expected = new DOMException(
'to \'optionalServices\' in requestDevice() options. https://goo.gl/HxfxSQ', 'to \'optionalServices\' in requestDevice() options. https://goo.gl/HxfxSQ',
'SecurityError'); 'SecurityError');
bluetooth_test(() => getHealthThermometerDevice({ bluetooth_test(() => getConnectedHealthThermometerDevice({
filters: [{services: ['health_thermometer']}] filters: [{services: ['health_thermometer']}]
}) })
.then(({device}) => Promise.all([ .then(({device}) => Promise.all([
......
...@@ -12,7 +12,7 @@ const expected = new DOMException( ...@@ -12,7 +12,7 @@ const expected = new DOMException(
'UUID to \'optionalServices\' in requestDevice() options. ' + 'UUID to \'optionalServices\' in requestDevice() options. ' +
'https://goo.gl/HxfxSQ', 'SecurityError'); 'https://goo.gl/HxfxSQ', 'SecurityError');
bluetooth_test(() => getHIDDevice({ bluetooth_test(() => getConnectedHIDDevice({
filters: [{services: ['device_information']}], filters: [{services: ['device_information']}],
optionalServices: ['human_interface_device'] optionalServices: ['human_interface_device']
}) })
......
...@@ -15,7 +15,7 @@ const expected = new DOMException( ...@@ -15,7 +15,7 @@ const expected = new DOMException(
'NetworkError'); 'NetworkError');
let device; let device;
bluetooth_test(() => getHealthThermometerDevice({ bluetooth_test(() => getConnectedHealthThermometerDevice({
filters: [{services: ['health_thermometer']}], filters: [{services: ['health_thermometer']}],
optionalServices: ['generic_access'] optionalServices: ['generic_access']
}) })
......
...@@ -15,7 +15,7 @@ const expected = new DOMException( ...@@ -15,7 +15,7 @@ const expected = new DOMException(
'NetworkError'); 'NetworkError');
let device; let device;
bluetooth_test(() => getHealthThermometerDevice({ bluetooth_test(() => getConnectedHealthThermometerDevice({
filters: [{services: ['health_thermometer']}], filters: [{services: ['health_thermometer']}],
optionalServices: ['generic_access'] optionalServices: ['generic_access']
}) })
......
...@@ -19,7 +19,7 @@ const expected = new DOMException( ...@@ -19,7 +19,7 @@ const expected = new DOMException(
" e.g. 'alert_notification'.", " e.g. 'alert_notification'.",
'TypeError'); 'TypeError');
bluetooth_test(() => getHealthThermometerDevice() bluetooth_test(() => getConnectedHealthThermometerDevice()
.then(({device}) => assert_promise_rejects_with_message( .then(({device}) => assert_promise_rejects_with_message(
device.gatt.getPrimaryServices('wrong_name'), device.gatt.getPrimaryServices('wrong_name'),
expected, expected,
......
...@@ -15,7 +15,7 @@ const expected = new DOMException( ...@@ -15,7 +15,7 @@ const expected = new DOMException(
'https://goo.gl/HxfxSQ', 'https://goo.gl/HxfxSQ',
'SecurityError'); 'SecurityError');
bluetooth_test(() => getHealthThermometerDevice({ bluetooth_test(() => getConnectedHealthThermometerDevice({
filters: [{services: ['health_thermometer']}] filters: [{services: ['health_thermometer']}]
}) })
.then(({device}) => Promise.all([ .then(({device}) => Promise.all([
......
...@@ -15,7 +15,7 @@ const expected = new DOMException( ...@@ -15,7 +15,7 @@ const expected = new DOMException(
'https://goo.gl/HxfxSQ', 'https://goo.gl/HxfxSQ',
'SecurityError'); 'SecurityError');
bluetooth_test(() => getHealthThermometerDevice({acceptAllDevices: true}) bluetooth_test(() => getConnectedHealthThermometerDevice({acceptAllDevices: true})
.then(({device}) => assert_promise_rejects_with_message( .then(({device}) => assert_promise_rejects_with_message(
device.gatt.getPrimaryServices('heart_rate'), device.gatt.getPrimaryServices('heart_rate'),
expected)), expected)),
......
...@@ -15,7 +15,7 @@ const expected = new DOMException( ...@@ -15,7 +15,7 @@ const expected = new DOMException(
'https://goo.gl/HxfxSQ', 'https://goo.gl/HxfxSQ',
'SecurityError'); 'SecurityError');
bluetooth_test(() => getHealthThermometerDevice({acceptAllDevices: true}) bluetooth_test(() => getConnectedHealthThermometerDevice({acceptAllDevices: true})
.then(({device}) => assert_promise_rejects_with_message( .then(({device}) => assert_promise_rejects_with_message(
device.gatt.getPrimaryServices(), device.gatt.getPrimaryServices(),
expected)), expected)),
......
...@@ -14,7 +14,7 @@ const expected = new DOMException( ...@@ -14,7 +14,7 @@ const expected = new DOMException(
'to \'optionalServices\' in requestDevice() options. https://goo.gl/HxfxSQ', 'to \'optionalServices\' in requestDevice() options. https://goo.gl/HxfxSQ',
'SecurityError'); 'SecurityError');
bluetooth_test(() => getHealthThermometerDevice({ bluetooth_test(() => getConnectedHealthThermometerDevice({
filters: [{services: ['health_thermometer']}] filters: [{services: ['health_thermometer']}]
}) })
.then(({device}) => Promise.all([ .then(({device}) => Promise.all([
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment