Commit e88a3fb5 authored by Ovidio Henriquez's avatar Ovidio Henriquez Committed by Commit Bot

bluetooth: web: test: Pre-migration formatting

This change ensures that tests that are ready to be migrated into wpt/
will contain consistent formatting. This includes a test_desc constant
describing the test and consistent indentation.

BUG=509038

Change-Id: If04b5cdd796709b8080960550cf216297e8d38f6
Reviewed-on: https://chromium-review.googlesource.com/891989
Commit-Queue: Ovidio Henriquez <odejesush@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarConley Owens <cco3@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533179}
parent 744fd440
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
<script src="../../resources/testharnessreport.js"></script> <script src="../../resources/testharnessreport.js"></script>
<script src="../../resources/testdriver.js"></script> <script src="../../resources/testdriver.js"></script>
<script src="../../resources/testdriver-vendor.js"></script> <script src="../../resources/testdriver-vendor.js"></script>
<script src="../../resources/bluetooth/bluetooth-helpers.js"></script>
<script src="../../external/wpt/bluetooth/resources/bluetooth-helpers.js"></script> <script src="../../external/wpt/bluetooth/resources/bluetooth-helpers.js"></script>
<script> <script>
'use strict'; 'use strict';
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
<script src="../../resources/testharnessreport.js"></script> <script src="../../resources/testharnessreport.js"></script>
<script src="../../resources/testdriver.js"></script> <script src="../../resources/testdriver.js"></script>
<script src="../../resources/testdriver-vendor.js"></script> <script src="../../resources/testdriver-vendor.js"></script>
<script src="../../resources/bluetooth/bluetooth-helpers.js"></script>
<script src="../../external/wpt/bluetooth/resources/bluetooth-helpers.js"></script> <script src="../../external/wpt/bluetooth/resources/bluetooth-helpers.js"></script>
<script> <script>
'use strict'; 'use strict';
......
...@@ -6,16 +6,16 @@ ...@@ -6,16 +6,16 @@
<script src="../../../external/wpt/bluetooth/resources/bluetooth-helpers.js"></script> <script src="../../../external/wpt/bluetooth/resources/bluetooth-helpers.js"></script>
<script> <script>
'use strict'; 'use strict';
bluetooth_test(() => { const test_desc = 'A read request succeeds and returns the descriptor\'s value.';
const EXPECTED_VALUE = [0, 1, 2]; const EXPECTED_VALUE = [0, 1, 2];
return getUserDescriptionDescriptor() let descriptor, fake_descriptor;
.then(({descriptor, fake_descriptor}) => {
return fake_descriptor.setNextReadResponse(GATT_SUCCESS, EXPECTED_VALUE) bluetooth_test(() => getUserDescriptionDescriptor()
.then(() => descriptor.readValue()) .then(_ => ({descriptor, fake_descriptor} = _))
.then(value => { .then(() =>
assert_array_equals(Array.from(new Uint8Array( fake_descriptor.setNextReadResponse(GATT_SUCCESS, EXPECTED_VALUE))
value.buffer)), EXPECTED_VALUE); .then(() => descriptor.readValue())
}); .then(value => assert_array_equals(Array.from(new Uint8Array(
}); value.buffer)), EXPECTED_VALUE)),
}, 'A read request succeeds and returns the descriptor\'s value.'); test_desc);
</script> </script>
...@@ -6,14 +6,14 @@ ...@@ -6,14 +6,14 @@
<script src="../../../external/wpt/bluetooth/resources/bluetooth-helpers.js"></script> <script src="../../../external/wpt/bluetooth/resources/bluetooth-helpers.js"></script>
<script> <script>
'use strict'; 'use strict';
let 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.';
let device, fake_peripheral;
bluetooth_test(() => getHealthThermometerDevice() bluetooth_test(() => getHealthThermometerDevice()
.then(_ => ({device, fake_peripheral} = _)) .then(({device, fake_peripheral}) => {
.then(() => {
fake_peripheral.simulateGATTDisconnection(); fake_peripheral.simulateGATTDisconnection();
return eventPromise(device, 'gattserverdisconnected'); return eventPromise(device, 'gattserverdisconnected');
}) })
.then(e => assert_true(e.bubbles)), test_desc); .then(e => assert_true(e.bubbles)),
test_desc);
</script> </script>
...@@ -6,12 +6,11 @@ ...@@ -6,12 +6,11 @@
<script src="../../../external/wpt/bluetooth/resources/bluetooth-helpers.js"></script> <script src="../../../external/wpt/bluetooth/resources/bluetooth-helpers.js"></script>
<script> <script>
'use strict'; 'use strict';
let test_desc = 'A device disconnecting after the BluetoothDevice object has ' + const test_desc = 'A device disconnecting after the BluetoothDevice object ' +
'been gced should not access freed memory.'; 'has been GC\'ed should not access freed memory.';
let fake_peripheral;
bluetooth_test(() => getHealthThermometerDevice() bluetooth_test(() => getHealthThermometerDevice()
.then(_ => ({fake_peripheral} = _)) .then(({fake_peripheral}) => {
.then(() => {
// 1. Disconnect. // 1. Disconnect.
fake_peripheral.simulateGATTDisconnection(); fake_peripheral.simulateGATTDisconnection();
// 2. Run garbage collection. // 2. Run garbage collection.
...@@ -20,5 +19,6 @@ bluetooth_test(() => getHealthThermometerDevice() ...@@ -20,5 +19,6 @@ bluetooth_test(() => getHealthThermometerDevice()
}) })
// 3. Wait 50ms after the GC runs for the disconnection event to come back. // 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. // There's nothing to assert other than that only valid memory is used.
.then(() => new Promise(resolve => step_timeout(resolve, 50))), test_desc); .then(() => new Promise(resolve => step_timeout(resolve, 50))),
test_desc);
</script> </script>
...@@ -6,16 +6,17 @@ ...@@ -6,16 +6,17 @@
<script src="../../../external/wpt/bluetooth/resources/bluetooth-helpers.js"></script> <script src="../../../external/wpt/bluetooth/resources/bluetooth-helpers.js"></script>
<script> <script>
'use strict'; 'use strict';
let test_desc = 'If a site disconnects from a device while the platform is ' + const test_desc = 'If a site disconnects from a device while the platform is ' +
'disconnecting that device, only one gattserverdisconnected event should ' + 'disconnecting that device, only one gattserverdisconnected event should ' +
'fire.'; 'fire.';
let device, fake_peripheral; let device, fake_peripheral;
let num_events = 0; let num_events = 0;
bluetooth_test(() => getHealthThermometerDevice() bluetooth_test(() => getHealthThermometerDevice()
.then(_ => ({device, fake_peripheral} = _)) .then(_ => ({device, fake_peripheral} = _))
// 1. Listen for disconnections. // 1. Listen for disconnections.
.then(() => .then(() =>
device.addEventListener('gattserverdisconnected', () => num_events++)) device.addEventListener('gattserverdisconnected', () => num_events++))
// 2. Disconnect several times. // 2. Disconnect several times.
.then(() => Promise.all([ .then(() => Promise.all([
eventPromise(device, 'gattserverdisconnected'), eventPromise(device, 'gattserverdisconnected'),
...@@ -26,5 +27,6 @@ bluetooth_test(() => getHealthThermometerDevice() ...@@ -26,5 +27,6 @@ bluetooth_test(() => getHealthThermometerDevice()
// 3. Wait to catch disconnect events. // 3. Wait to catch disconnect events.
.then(() => new Promise(resolve => step_timeout(resolve, 50))) .then(() => new Promise(resolve => step_timeout(resolve, 50)))
// 4. Ensure there is exactly 1 disconnection recorded. // 4. Ensure there is exactly 1 disconnection recorded.
.then(() => assert_equals(num_events, 1)), test_desc); .then(() => assert_equals(num_events, 1)),
test_desc);
</script> </script>
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
<script src="../../resources/testharnessreport.js"></script> <script src="../../resources/testharnessreport.js"></script>
<script src="../../resources/testdriver.js"></script> <script src="../../resources/testdriver.js"></script>
<script src="../../resources/testdriver-vendor.js"></script> <script src="../../resources/testdriver-vendor.js"></script>
<script src="../../resources/bluetooth/bluetooth-helpers.js"></script>
<script src="../../external/wpt/bluetooth/resources/bluetooth-helpers.js"></script> <script src="../../external/wpt/bluetooth/resources/bluetooth-helpers.js"></script>
<script> <script>
'use strict'; 'use strict';
const test_desc_idl = 'BluetoothDevice IDL test.'; const test_desc_idl = 'BluetoothDevice IDL test.';
test(() => { test(() => {
assert_throws(new TypeError(), () => new BluetoothDevice(), assert_throws(new TypeError(), () => new BluetoothDevice(),
'the constructor should not be callable with "new"'); 'the constructor should not be callable with "new"');
...@@ -18,15 +18,14 @@ test(() => { ...@@ -18,15 +18,14 @@ test(() => {
const test_desc_attr = 'BluetoothDevice attributes.'; const test_desc_attr = 'BluetoothDevice attributes.';
let device; let device;
bluetooth_test(() => getHealthThermometerDevice() bluetooth_test(() => getHealthThermometerDevice()
.then(_ => ({device} = _)) .then(({device}) => {
.then(() => {
assert_equals(device.constructor.name, 'BluetoothDevice'); assert_equals(device.constructor.name, 'BluetoothDevice');
var old_device_id = device.id; var old_device_id = device.id;
assert_throws(new TypeError(), () => device.id = 'overwritten', assert_throws(new TypeError(), () => device.id = 'overwritten',
'the device id should not be writable'); 'the device id should not be writable');
assert_throws(new TypeError(), () => device.name = 'overwritten', assert_throws(new TypeError(), () => device.name = 'overwritten',
'the device name should not be writable'); 'the device name should not be writable');
assert_equals(device.id, old_device_id); assert_equals(device.id, old_device_id);
assert_equals(device.name, 'Health Thermometer'); assert_equals(device.name, 'Health Thermometer');
}), test_desc_attr); }), test_desc_attr);
</script> </script>
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
<script src="../../resources/testharnessreport.js"></script> <script src="../../resources/testharnessreport.js"></script>
<script src="../../resources/testdriver.js"></script> <script src="../../resources/testdriver.js"></script>
<script src="../../resources/testdriver-vendor.js"></script> <script src="../../resources/testdriver-vendor.js"></script>
<script src="../../resources/bluetooth/bluetooth-helpers.js"></script>
<script src="../../external/wpt/bluetooth/resources/bluetooth-helpers.js"></script> <script src="../../external/wpt/bluetooth/resources/bluetooth-helpers.js"></script>
<script> <script>
'use strict'; 'use strict';
bluetooth_test(() => { const test_desc = 'Same parent device returned from multiple services.';
return getTwoHealthThermometerServicesDevice({
filters: [{services: ['health_thermometer']}]}) bluetooth_test(() => getTwoHealthThermometerServicesDevice({
filters: [{services: ['health_thermometer']}]
})
.then(({device}) => device.gatt.getPrimaryServices('health_thermometer')) .then(({device}) => device.gatt.getPrimaryServices('health_thermometer'))
.then(([service1, service2]) => { .then(([service1, service2]) =>
assert_equals(service1.device, service2.device); assert_equals(service1.device, service2.device)),
}); test_desc);
}, "Same parent device returned from multiple services.");
</script> </script>
...@@ -3,16 +3,15 @@ ...@@ -3,16 +3,15 @@
<script src="../../resources/testharnessreport.js"></script> <script src="../../resources/testharnessreport.js"></script>
<script src="../../resources/testdriver.js"></script> <script src="../../resources/testdriver.js"></script>
<script src="../../resources/testdriver-vendor.js"></script> <script src="../../resources/testdriver-vendor.js"></script>
<script src="../../resources/bluetooth/bluetooth-helpers.js"></script>
<script src="../../external/wpt/bluetooth/resources/bluetooth-helpers.js"></script> <script src="../../external/wpt/bluetooth/resources/bluetooth-helpers.js"></script>
<script> <script>
'use strict'; 'use strict';
bluetooth_test(() => { const test_desc = '[SameObject] test for BluetoothRemoteGATTService device.';
return getHealthThermometerDevice({
filters: [{services: ['health_thermometer']}]}) bluetooth_test(() => getHealthThermometerDevice({
filters: [{services: ['health_thermometer']}]
})
.then(({device}) => device.gatt.getPrimaryService('health_thermometer')) .then(({device}) => device.gatt.getPrimaryService('health_thermometer'))
.then(service => { .then(service => assert_equals(service.device, service.device)),
assert_equals(service.device, service.device); test_desc);
});
}, "[SameObject] test for BluetoothRemoteGATTService's device.");
</script> </script>
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