Added some new tests for a few WebBluetooth method.

This commit is contained in:
Valentin Fokin 2016-12-14 12:42:07 +01:00 committed by Attila Dusnoki
parent 23590f683a
commit bc948f7975
22 changed files with 413 additions and 8 deletions

View file

@ -6860,6 +6860,12 @@
"url": "/_mozilla/mozilla/bluetooth/getCharacteristic/invalid-characteristic-name.html"
}
],
"mozilla/bluetooth/getCharacteristic/reconnect-during.html": [
{
"path": "mozilla/bluetooth/getCharacteristic/reconnect-during.html",
"url": "/_mozilla/mozilla/bluetooth/getCharacteristic/reconnect-during.html"
}
],
"mozilla/bluetooth/getCharacteristic/service-is-removed.html": [
{
"path": "mozilla/bluetooth/getCharacteristic/service-is-removed.html",
@ -7310,6 +7316,12 @@
"url": "/_mozilla/mozilla/bluetooth/getPrimaryServices/get-different-services-after-reconnection.html"
}
],
"mozilla/bluetooth/getPrimaryServices/get-same-service-with-uuid.html": [
{
"path": "mozilla/bluetooth/getPrimaryServices/get-same-service-with-uuid.html",
"url": "/_mozilla/mozilla/bluetooth/getPrimaryServices/get-same-service-with-uuid.html"
}
],
"mozilla/bluetooth/getPrimaryServices/get-same-service.html": [
{
"path": "mozilla/bluetooth/getPrimaryServices/get-same-service.html",
@ -7394,6 +7406,12 @@
"url": "/_mozilla/mozilla/bluetooth/readValue/characteristic/disconnect-called-before.html"
}
],
"mozilla/bluetooth/readValue/characteristic/disconnect-called-during.html": [
{
"path": "mozilla/bluetooth/readValue/characteristic/disconnect-called-during.html",
"url": "/_mozilla/mozilla/bluetooth/readValue/characteristic/disconnect-called-during.html"
}
],
"mozilla/bluetooth/readValue/characteristic/event-is-fired.html": [
{
"path": "mozilla/bluetooth/readValue/characteristic/event-is-fired.html",
@ -7466,16 +7484,46 @@
"url": "/_mozilla/mozilla/bluetooth/readValue/descriptor/service-is-removed.html"
}
],
"mozilla/bluetooth/requestDevice/accept-all-devices-with-filter.html": [
"mozilla/bluetooth/requestDevice/acceptAllDevices/accept-all-devices-with-filter.html": [
{
"path": "mozilla/bluetooth/requestDevice/accept-all-devices-with-filter.html",
"url": "/_mozilla/mozilla/bluetooth/requestDevice/accept-all-devices-with-filter.html"
"path": "mozilla/bluetooth/requestDevice/acceptAllDevices/accept-all-devices-with-filter.html",
"url": "/_mozilla/mozilla/bluetooth/requestDevice/acceptAllDevices/accept-all-devices-with-filter.html"
}
],
"mozilla/bluetooth/requestDevice/accept-all-devices.html": [
"mozilla/bluetooth/requestDevice/acceptAllDevices/accept-all-devices.html": [
{
"path": "mozilla/bluetooth/requestDevice/accept-all-devices.html",
"url": "/_mozilla/mozilla/bluetooth/requestDevice/accept-all-devices.html"
"path": "mozilla/bluetooth/requestDevice/acceptAllDevices/accept-all-devices.html",
"url": "/_mozilla/mozilla/bluetooth/requestDevice/acceptAllDevices/accept-all-devices.html"
}
],
"mozilla/bluetooth/requestDevice/acceptAllDevices/device-with-empty-name.html": [
{
"path": "mozilla/bluetooth/requestDevice/acceptAllDevices/device-with-empty-name.html",
"url": "/_mozilla/mozilla/bluetooth/requestDevice/acceptAllDevices/device-with-empty-name.html"
}
],
"mozilla/bluetooth/requestDevice/acceptAllDevices/device-with-name.html": [
{
"path": "mozilla/bluetooth/requestDevice/acceptAllDevices/device-with-name.html",
"url": "/_mozilla/mozilla/bluetooth/requestDevice/acceptAllDevices/device-with-name.html"
}
],
"mozilla/bluetooth/requestDevice/acceptAllDevices/device-with-no-name.html": [
{
"path": "mozilla/bluetooth/requestDevice/acceptAllDevices/device-with-no-name.html",
"url": "/_mozilla/mozilla/bluetooth/requestDevice/acceptAllDevices/device-with-no-name.html"
}
],
"mozilla/bluetooth/requestDevice/acceptAllDevices/optional-services-missing.html": [
{
"path": "mozilla/bluetooth/requestDevice/acceptAllDevices/optional-services-missing.html",
"url": "/_mozilla/mozilla/bluetooth/requestDevice/acceptAllDevices/optional-services-missing.html"
}
],
"mozilla/bluetooth/requestDevice/acceptAllDevices/optional-services-present.html": [
{
"path": "mozilla/bluetooth/requestDevice/acceptAllDevices/optional-services-present.html",
"url": "/_mozilla/mozilla/bluetooth/requestDevice/acceptAllDevices/optional-services-present.html"
}
],
"mozilla/bluetooth/requestDevice/adapter-not-present.html": [
@ -7532,6 +7580,12 @@
"url": "/_mozilla/mozilla/bluetooth/requestDevice/canonicalizeFilter/empty-services-member.html"
}
],
"mozilla/bluetooth/requestDevice/canonicalizeFilter/filters-xor-acceptAllDevices.html": [
{
"path": "mozilla/bluetooth/requestDevice/canonicalizeFilter/filters-xor-acceptAllDevices.html",
"url": "/_mozilla/mozilla/bluetooth/requestDevice/canonicalizeFilter/filters-xor-acceptAllDevices.html"
}
],
"mozilla/bluetooth/requestDevice/canonicalizeFilter/max-length-for-device-name-name.html": [
{
"path": "mozilla/bluetooth/requestDevice/canonicalizeFilter/max-length-for-device-name-name.html",
@ -7790,12 +7844,24 @@
"url": "/_mozilla/mozilla/bluetooth/startNotifications/blocklisted-characteristic.html"
}
],
"mozilla/bluetooth/startNotifications/characteristic-does-not-support-notifications.html": [
{
"path": "mozilla/bluetooth/startNotifications/characteristic-does-not-support-notifications.html",
"url": "/_mozilla/mozilla/bluetooth/startNotifications/characteristic-does-not-support-notifications.html"
}
],
"mozilla/bluetooth/startNotifications/characteristic-is-removed.html": [
{
"path": "mozilla/bluetooth/startNotifications/characteristic-is-removed.html",
"url": "/_mozilla/mozilla/bluetooth/startNotifications/characteristic-is-removed.html"
}
],
"mozilla/bluetooth/startNotifications/device-goes-out-of-range.html": [
{
"path": "mozilla/bluetooth/startNotifications/device-goes-out-of-range.html",
"url": "/_mozilla/mozilla/bluetooth/startNotifications/device-goes-out-of-range.html"
}
],
"mozilla/bluetooth/startNotifications/disconnect-called-before.html": [
{
"path": "mozilla/bluetooth/startNotifications/disconnect-called-before.html",
@ -7820,6 +7886,12 @@
"url": "/_mozilla/mozilla/bluetooth/startNotifications/notify-succeeds.html"
}
],
"mozilla/bluetooth/startNotifications/service-is-removed.html": [
{
"path": "mozilla/bluetooth/startNotifications/service-is-removed.html",
"url": "/_mozilla/mozilla/bluetooth/startNotifications/service-is-removed.html"
}
],
"mozilla/bluetooth/stopNotifications/characteristic-is-removed.html": [
{
"path": "mozilla/bluetooth/stopNotifications/characteristic-is-removed.html",
@ -7844,6 +7916,24 @@
"url": "/_mozilla/mozilla/bluetooth/stopNotifications/notify-succeeds.html"
}
],
"mozilla/bluetooth/stopNotifications/stop-after-start-succeeds.html": [
{
"path": "mozilla/bluetooth/stopNotifications/stop-after-start-succeeds.html",
"url": "/_mozilla/mozilla/bluetooth/stopNotifications/stop-after-start-succeeds.html"
}
],
"mozilla/bluetooth/stopNotifications/stop-twice.html": [
{
"path": "mozilla/bluetooth/stopNotifications/stop-twice.html",
"url": "/_mozilla/mozilla/bluetooth/stopNotifications/stop-twice.html"
}
],
"mozilla/bluetooth/stopNotifications/stop-without-starting.html": [
{
"path": "mozilla/bluetooth/stopNotifications/stop-without-starting.html",
"url": "/_mozilla/mozilla/bluetooth/stopNotifications/stop-without-starting.html"
}
],
"mozilla/bluetooth/writeValue/characteristic/blocklisted-characteristic.html": [
{
"path": "mozilla/bluetooth/writeValue/characteristic/blocklisted-characteristic.html",
@ -7874,6 +7964,12 @@
"url": "/_mozilla/mozilla/bluetooth/writeValue/characteristic/service-is-removed.html"
}
],
"mozilla/bluetooth/writeValue/characteristic/value-too-long.html": [
{
"path": "mozilla/bluetooth/writeValue/characteristic/value-too-long.html",
"url": "/_mozilla/mozilla/bluetooth/writeValue/characteristic/value-too-long.html"
}
],
"mozilla/bluetooth/writeValue/characteristic/write-succeeds.html": [
{
"path": "mozilla/bluetooth/writeValue/characteristic/write-succeeds.html",

View file

@ -0,0 +1,5 @@
[reconnect-during.html]
type: testharness
[disconnect() and connect() called during getCharacteristic. Reject with NetworkError.]
expected: FAIL

View file

@ -0,0 +1,5 @@
[disconnect-called-during.html]
type: testharness
[disconnect() called during readValue. Reject with NetworkError.]
expected: FAIL

View file

@ -0,0 +1,23 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(t => {
window.testRunner.setBluetoothMockDataSet(adapter_type.heart_rate);
return window.navigator.bluetooth.requestDevice({
filters: [{services: [heart_rate.name]}],
})
.then(device => device.gatt.connect())
.then(gattServer => {
return gattServer.getPrimaryService(heart_rate.name)
.then(service => {
let promise = promise_rejects(t, 'NetworkError', service.getCharacteristic(heart_rate_measurement.uuid));
gattServer.disconnect();
return gattServer.connect()
.then(() => promise);
});
});
}, 'disconnect() and connect() called during getCharacteristic. Reject with NetworkError.');
</script>

View file

@ -0,0 +1,18 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(() => {
window.testRunner.setBluetoothMockDataSet(adapter_type.two_heart_rate);
return window.navigator.bluetooth.requestDevice({
filters: [{services: [heart_rate.name]}]
})
.then(device => device.gatt.connect())
.then(gattServer => Promise.all([
gattServer.getPrimaryServices(heart_rate.name),
gattServer.getPrimaryServices(heart_rate.name)]))
.then(services => assert_array_equals(services[0], services[1]));
}, 'Calls to get the same service should return the same object.');
</script>

View file

@ -11,8 +11,8 @@ promise_test(() => {
})
.then(device => device.gatt.connect())
.then(gattServer => Promise.all([
gattServer.getPrimaryServices(heart_rate.name),
gattServer.getPrimaryServices(heart_rate.name)]))
gattServer.getPrimaryServices(),
gattServer.getPrimaryServices()]))
.then(services => assert_array_equals(services[0], services[1]));
}, 'Calls to get the same service should return the same object.');
</script>

View file

@ -0,0 +1,25 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(t => {
window.testRunner.setBluetoothMockDataSet(adapter_type.heart_rate);
return window.navigator.bluetooth.requestDevice({
filters: [{services: [heart_rate.name]}],
optionalServices: [generic_access.name]
})
.then(device => device.gatt.connect())
.then(gattServer => {
return gattServer.getPrimaryService(heart_rate.name)
.then(service => service.getCharacteristic(heart_rate_measurement.name))
.then(characteristic => characteristic.startNotifications())
.then(characteristic => {
let promise = promise_rejects(t, 'NetworkError', characteristic.readValue());
gattServer.disconnect();
return promise;
});
});
}, 'disconnect() called during readValue. Reject with NetworkError.');
</script>

View file

@ -0,0 +1,12 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(() => {
window.testRunner.setBluetoothMockDataSet(adapter_type.empty_name_heart_rate);
return window.navigator.bluetooth.requestDevice({acceptAllDevices: true})
.then(device => assert_equals(device.name, ''));
}, 'Device with empty name and no UUIDs nearby. Should be found if acceptAllDevices is true.');
</script>

View file

@ -0,0 +1,13 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(() => {
let device_name = '\u2764'.repeat(9);
window.testRunner.setBluetoothMockDataSet(adapter_type.unicode_device);
return window.navigator.bluetooth.requestDevice({acceptAllDevices: true})
.then(device => assert_equals(device.name, device_name));
}, 'Device with name and no UUIDs nearby. Should be found if acceptAllDevices is true.');
</script>

View file

@ -0,0 +1,12 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(() => {
window.testRunner.setBluetoothMockDataSet(adapter_type.no_name_heart_rate);
return window.navigator.bluetooth.requestDevice({acceptAllDevices: true})
.then(device => assert_equals(device.name, null));
}, 'Device with no name or UUIDs nearby. Should be found if acceptAllDevices is true.');
</script>

View file

@ -0,0 +1,13 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(t => {
window.testRunner.setBluetoothMockDataSet(adapter_type.two_heart_rate);
return window.navigator.bluetooth.requestDevice({acceptAllDevices: true})
.then(device => device.gatt.connect())
.then(gattServer => promise_rejects(t, 'NotFoundError', gattServer.getPrimaryServices()));
}, 'requestDevice called with acceptAllDevices: true and with no optionalServices. Should not get access to any services.');
</script>

View file

@ -0,0 +1,22 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(() => {
window.testRunner.setBluetoothMockDataSet(adapter_type.two_heart_rate);
return window.navigator.bluetooth.requestDevice({
acceptAllDevices: true,
optionalServices: ['heart_rate']
})
.then(device => device.gatt.connect())
.then(gattServer => gattServer.getPrimaryServices())
.then(services => {
assert_equals(services.length, 2);
services.forEach(service => {
assert_equals(service.uuid, BluetoothUUID.getService('heart_rate'));
});
})
}, 'requestDevice called with acceptAllDevices: true and with optionalServices. Should get access to services.');
</script>

View file

@ -0,0 +1,16 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(t => {
window.testRunner.setBluetoothMockDataSet(adapter_type.glucose_heart_rate);
return promise_rejects(t, new TypeError(), window.navigator.bluetooth.requestDevice({
filters: [{services: [battery_service.name]},
{services: [heart_rate.name]},
{acceptAllDevices: true},
{acceptAllDevices: true, optionalServices: ['heart_rate']}]
}));
}, 'RequestDeviceOptions should have exactly one of \'filters\' or \'acceptAllDevices:true\'. Reject with TypeError if not.');
</script>

View file

@ -0,0 +1,20 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(t => {
window.testRunner.setBluetoothMockDataSet(adapter_type.heart_rate);
return window.navigator.bluetooth.requestDevice({
filters: [{services: [heart_rate.name]}],
optionalServices: [generic_access.name]
})
.then(device => device.gatt.connect())
.then(gattServer => gattServer.getPrimaryService(heart_rate.name))
.then(service => service.getCharacteristic(body_sensor_location.name))
.then(characteristic => {
return promise_rejects(t, 'NotSupportedError', characteristic.startNotifications());
});
}, 'Characteristic doesn\'t support Notifications. Reject with NotSupportedError.');
</script>

View file

@ -0,0 +1,20 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(t => {
window.testRunner.setBluetoothMockDataSet(adapter_type.heart_rate);
return window.navigator.bluetooth.requestDevice({
filters: [{services: [heart_rate.name]}]
})
.then(device => device.gatt.connect())
.then(gattServer => gattServer.getPrimaryService(heart_rate.name))
.then(service => service.getCharacteristic(heart_rate_measurement.name))
.then(characteristic => {
window.testRunner.setBluetoothMockDataSet(adapter_type.empty);
return promise_rejects(t, 'InvalidStateError', characteristic.startNotifications());
});
}, 'Device goes out of range. Reject with InvalidStateError.');
</script>

View file

@ -0,0 +1,21 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(t => {
window.testRunner.setBluetoothMockDataSet(adapter_type.heart_rate);
return window.navigator.bluetooth.requestDevice({
filters: [{services: [heart_rate.name]}],
optionalServices: [generic_access.name]
})
.then(device => device.gatt.connect())
.then(gattServer => gattServer.getPrimaryService(heart_rate.name))
.then(service => service.getCharacteristic(heart_rate_measurement.name))
.then(characteristic => {
window.testRunner.setBluetoothMockDataSet(adapter_type.missing_service_heart_rate);
return promise_rejects(t, 'InvalidStateError', characteristic.startNotifications());
});
}, 'Service gets removed. Reject with InvalidStateError.');
</script>

View file

@ -0,0 +1,25 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(() => {
window.testRunner.setBluetoothMockDataSet(adapter_type.heart_rate);
return window.navigator.bluetooth.requestDevice({
filters: [{services: [heart_rate.name]}],
optionalServices: [generic_access.name]
})
.then(device => device.gatt.connect())
.then(gattServer => gattServer.getPrimaryService(heart_rate.name))
.then(service => service.getCharacteristic(heart_rate_measurement.name))
.then(characteristic => {
return characteristic.startNotifications()
.then(start_characteristic => {
assert_equals(start_characteristic, characteristic);
return characteristic.stopNotifications()
.then(stop_characteristic => assert_equals(stop_characteristic, start_characteristic));
});
});
}, 'Single stop after start notifications succeeds.');
</script>

View file

@ -0,0 +1,22 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(() => {
window.testRunner.setBluetoothMockDataSet(adapter_type.heart_rate);
return window.navigator.bluetooth.requestDevice({
filters: [{services: [heart_rate.name]}],
optionalServices: [generic_access.name]
})
.then(device => device.gatt.connect())
.then(gattServer => gattServer.getPrimaryService(heart_rate.name))
.then(service => service.getCharacteristic(heart_rate_measurement.name))
.then(characteristic => {
return characteristic.startNotifications()
.then(() => characteristic.stopNotifications())
.then(() => characteristic.stopNotifications());
});
}, 'Stopping twice.');
</script>

View file

@ -0,0 +1,18 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(() => {
window.testRunner.setBluetoothMockDataSet(adapter_type.heart_rate);
return window.navigator.bluetooth.requestDevice({
filters: [{services: [heart_rate.name]}],
optionalServices: [generic_access.name]
})
.then(device => device.gatt.connect())
.then(gattServer => gattServer.getPrimaryService(heart_rate.name))
.then(service => service.getCharacteristic(heart_rate_measurement.name))
.then(characteristic => characteristic.stopNotifications());
}, 'Stop without starting.');
</script>

View file

@ -0,0 +1,19 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(t => {
window.testRunner.setBluetoothMockDataSet(adapter_type.heart_rate);
return window.navigator.bluetooth.requestDevice({
filters: [{services: [heart_rate.name]}],
optionalServices: [generic_access.name]
})
.then(device => device.gatt.connect())
.then(gattServer => gattServer.getPrimaryService(generic_access.name))
.then(service => service.getCharacteristic(device_name.name))
.then(characteristic =>
promise_rejects(t, 'InvalidModificationError', characteristic.writeValue(new Uint8Array(513))));
}, 'Trying to write more than 512 bytes should return an InvalidModificationError.');
</script>