Skip to content

Commit

Permalink
Added some new tests for a few WebBluetooth method.
Browse files Browse the repository at this point in the history
  • Loading branch information
fokinv authored and dati91 committed Dec 22, 2016
1 parent 23590f6 commit bc948f7
Show file tree
Hide file tree
Showing 22 changed files with 413 additions and 8 deletions.
108 changes: 102 additions & 6 deletions tests/wpt/mozilla/meta/MANIFEST.json
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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/acceptAllDevices/accept-all-devices-with-filter.html",
"url": "/_mozilla/mozilla/bluetooth/requestDevice/acceptAllDevices/accept-all-devices-with-filter.html"
}
],
"mozilla/bluetooth/requestDevice/acceptAllDevices/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/accept-all-devices-with-filter.html",
"url": "/_mozilla/mozilla/bluetooth/requestDevice/accept-all-devices-with-filter.html"
"path": "mozilla/bluetooth/requestDevice/acceptAllDevices/optional-services-missing.html",
"url": "/_mozilla/mozilla/bluetooth/requestDevice/acceptAllDevices/optional-services-missing.html"
}
],
"mozilla/bluetooth/requestDevice/accept-all-devices.html": [
"mozilla/bluetooth/requestDevice/acceptAllDevices/optional-services-present.html": [
{
"path": "mozilla/bluetooth/requestDevice/accept-all-devices.html",
"url": "/_mozilla/mozilla/bluetooth/requestDevice/accept-all-devices.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": [
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
@@ -0,0 +1,5 @@
[reconnect-during.html]
type: testharness
[disconnect() and connect() called during getCharacteristic. Reject with NetworkError.]
expected: FAIL

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

@@ -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>
@@ -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>
Expand Up @@ -11,8 +11,8 @@
})
.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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>

0 comments on commit bc948f7

Please sign in to comment.