Skip to content

Commit

Permalink
bluetooth: Migrate remaining tests
Browse files Browse the repository at this point in the history
This change will migrate the remaining tests that have been converted
to the Web Bluetooth Test API at the moment.

BUG=509038

Change-Id: I6b38a9dd413f99caccbc9861d492eec0a25b1b91
Reviewed-on: https://chromium-review.googlesource.com/891653
Commit-Queue: Ovidio Henriquez <odejesush@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#538680}
  • Loading branch information
odejesush authored and chromium-wpt-export-bot committed Feb 23, 2018
1 parent 5496784 commit 99ea9dc
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 0 deletions.
@@ -0,0 +1,19 @@
<!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-helpers.js"></script>
<script>
'use strict';
const test_desc = 'Same parent service returned from multiple characteristics.';

bluetooth_test(() => getHealthThermometerService()
.then(({service}) => Promise.all([
service.getCharacteristic('measurement_interval'),
service.getCharacteristic('temperature_measurement')
]))
.then(characteristics =>
assert_equals(characteristics[0].service, characteristics[1].service)),
test_desc);
</script>
16 changes: 16 additions & 0 deletions bluetooth/characteristic/service-same-object.https.html
@@ -0,0 +1,16 @@
<!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-helpers.js"></script>
<script>
'use strict';
const test_desc = '[SameObject] test for BluetoothRemoteGATTCharacteristic ' +
'service.';

bluetooth_test(() => getMeasurementIntervalCharacteristic()
.then(({characteristic}) =>
assert_equals(characteristic.service, characteristic.service)),
test_desc);
</script>
21 changes: 21 additions & 0 deletions bluetooth/descriptor/readValue/read-succeeds.https.html
@@ -0,0 +1,21 @@
<!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-helpers.js"></script>
<script>
'use strict';
const test_desc = 'A read request succeeds and returns the descriptor\'s value.';
const EXPECTED_VALUE = [0, 1, 2];
let descriptor, fake_descriptor;

bluetooth_test(() => getUserDescriptionDescriptor()
.then(_ => ({descriptor, fake_descriptor} = _))
.then(() =>
fake_descriptor.setNextReadResponse(GATT_SUCCESS, EXPECTED_VALUE))
.then(() => descriptor.readValue())
.then(value => assert_array_equals(Array.from(new Uint8Array(
value.buffer)), EXPECTED_VALUE)),
test_desc);
</script>
@@ -0,0 +1,19 @@
<!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-helpers.js"></script>
<script>
'use strict';
const test_desc = 'A device disconnecting while connected should fire the ' +
'gattserverdisconnected event.';

bluetooth_test(() => getHealthThermometerDevice()
.then(({device, fake_peripheral}) => {
fake_peripheral.simulateGATTDisconnection();
return eventPromise(device, 'gattserverdisconnected');
})
.then(e => assert_true(e.bubbles)),
test_desc);
</script>
@@ -0,0 +1,24 @@
<!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-helpers.js"></script>
<script>
'use strict';
const test_desc = 'A device disconnecting after the BluetoothDevice object ' +
'has been GC\'ed should not access freed memory.';

bluetooth_test(() => getHealthThermometerDevice()
.then(({fake_peripheral}) => {
// 1. Disconnect.
fake_peripheral.simulateGATTDisconnection();
// 2. Run garbage collection.
fake_peripheral = undefined;
runGarbageCollection();
})
// 3. Wait 50ms after the GC runs for the disconnection event to come back.
// There's nothing to assert other than that only valid memory is used.
.then(() => new Promise(resolve => step_timeout(resolve, 50))),
test_desc);
</script>
@@ -0,0 +1,32 @@
<!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-helpers.js"></script>
<script>
'use strict';
const test_desc = 'If a site disconnects from a device while the platform is ' +
'disconnecting that device, only one gattserverdisconnected event should ' +
'fire.';
let device, fake_peripheral;
let num_events = 0;

bluetooth_test(() => getHealthThermometerDevice()
.then(_ => ({device, fake_peripheral} = _))
// 1. Listen for disconnections.
.then(() =>
device.addEventListener('gattserverdisconnected', () => num_events++))
// 2. Disconnect several times.
.then(() => Promise.all([
eventPromise(device, 'gattserverdisconnected'),
fake_peripheral.simulateGATTDisconnection(),
device.gatt.disconnect(),
device.gatt.disconnect(),
]))
// 3. Wait to catch disconnect events.
.then(() => new Promise(resolve => step_timeout(resolve, 50)))
// 4. Ensure there is exactly 1 disconnection recorded.
.then(() => assert_equals(num_events, 1)),
test_desc);
</script>
@@ -0,0 +1,34 @@
<!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-helpers.js"></script>
<script>
'use strict';
let test_desc = 'A device that reconnects during the gattserverdisconnected ' +
'event should still receive gattserverdisconnected events after ' +
're-connection.';
let device, fake_peripheral;
bluetooth_test(() => getHealthThermometerDevice()
.then(_ => ({device, fake_peripheral} = _))
// 1. Disconnect.
.then(() => new Promise(resolve => {
fake_peripheral.simulateGATTDisconnection();
device.addEventListener(
'gattserverdisconnected', function onDisconnected() {
device.removeEventListener('gattserverdisconnected', onDisconnected);
// 2. Reconnect.
fake_peripheral.setNextGATTConnectionResponse({
code: HCI_SUCCESS,
})
.then(() => device.gatt.connect())
.then(() => resolve());
});
}))
// 3. Disconnect after reconnecting.
.then(() => {
fake_peripheral.simulateGATTDisconnection();
return eventPromise(device, 'gattserverdisconnected')
}), test_desc);
</script>
31 changes: 31 additions & 0 deletions bluetooth/idl/idl-BluetoothDevice.https.html
@@ -0,0 +1,31 @@
<!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-helpers.js"></script>
<script>
'use strict';
const test_desc_idl = 'BluetoothDevice IDL test.';

test(() => {
assert_throws(new TypeError(), () => new BluetoothDevice(),
'the constructor should not be callable with "new"');
assert_throws(new TypeError(), () => BluetoothDevice(),
'the constructor should not be callable');
}, test_desc_idl);

const test_desc_attr = 'BluetoothDevice attributes.';
let device;
bluetooth_test(() => getHealthThermometerDevice()
.then(({device}) => {
assert_equals(device.constructor.name, 'BluetoothDevice');
var old_device_id = device.id;
assert_throws(new TypeError(), () => device.id = 'overwritten',
'the device id should not be writable');
assert_throws(new TypeError(), () => device.name = 'overwritten',
'the device name should not be writable');
assert_equals(device.id, old_device_id);
assert_equals(device.name, 'Health Thermometer');
}), test_desc_attr);
</script>
18 changes: 18 additions & 0 deletions bluetooth/service/device-same-from-2-services.https.html
@@ -0,0 +1,18 @@
<!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-helpers.js"></script>
<script>
'use strict';
const test_desc = 'Same parent device returned from multiple services.';

bluetooth_test(() => getTwoHealthThermometerServicesDevice({
filters: [{services: ['health_thermometer']}]
})
.then(({device}) => device.gatt.getPrimaryServices('health_thermometer'))
.then(([service1, service2]) =>
assert_equals(service1.device, service2.device)),
test_desc);
</script>
17 changes: 17 additions & 0 deletions bluetooth/service/device-same-object.https.html
@@ -0,0 +1,17 @@
<!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-helpers.js"></script>
<script>
'use strict';
const test_desc = '[SameObject] test for BluetoothRemoteGATTService device.';

bluetooth_test(() => getHealthThermometerDevice({
filters: [{services: ['health_thermometer']}]
})
.then(({device}) => device.gatt.getPrimaryService('health_thermometer'))
.then(service => assert_equals(service.device, service.device)),
test_desc);
</script>

0 comments on commit 99ea9dc

Please sign in to comment.