| Index: LayoutTests/bluetooth/getCharacteristic.html
|
| diff --git a/LayoutTests/bluetooth/getCharacteristic.html b/LayoutTests/bluetooth/getCharacteristic.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..403e7af4045284edcc3ad86b3b0a0813cf991b61
|
| --- /dev/null
|
| +++ b/LayoutTests/bluetooth/getCharacteristic.html
|
| @@ -0,0 +1,78 @@
|
| +<!DOCTYPE html>
|
| +<script src="../resources/testharness.js"></script>
|
| +<script src="../resources/testharnessreport.js"></script>
|
| +<script src="bluetooth-helpers.js"></script>
|
| +<script>
|
| +test(function(t) { assert_exists(window, "testRunner"); t.done(); },
|
| + "window.testRunner is required for the following tests.");
|
| +
|
| +// Generic Access Service.
|
| +var serviceUUID = "00001800-0000-1000-8000-00805f9b34fb";
|
| +// Device Name Characteristic. Belongs to Generic Access.
|
| +var includedCharacteristicUUID = "00002a00-0000-1000-8000-00805f9b34fb";
|
| +// Battery Level. Belongs to Battery Service.
|
| +var nonIncludedCharacteristicUUID = "00002a19-0000-1000-8000-00805f9b34fb";
|
| +
|
| +sequential_promise_test(function() {
|
| + testRunner.setBluetoothMockDataSet('ConnectableDeviceAdapter');
|
| + return navigator.bluetooth.requestDevice().then(function(device) {
|
| + return device.connectGATT();
|
| + }).then(function(gattServer) {
|
| + return gattServer.getPrimaryService(serviceUUID);
|
| + }).then(function(service) {
|
| + testRunner.setBluetoothMockDataSet('EmptyAdapter');
|
| + return service.getCharacteristic(includedCharacteristicUUID).then(function() {
|
| + assert_unreached("Device went out of range, should fail.");
|
| + }, function(e) {
|
| + assert_equals(e.name, "NetworkError");
|
| + });
|
| + });
|
| +}, 'Device goes out of range. Reject with NetworkError.');
|
| +
|
| +sequential_promise_test(function() {
|
| + testRunner.setBluetoothMockDataSet('ConnectableDeviceAdapter');
|
| + return navigator.bluetooth.requestDevice().then(function(device) {
|
| + return device.connectGATT();
|
| + }).then(function(gattServer) {
|
| + return gattServer.getPrimaryService(serviceUUID);
|
| + }).then(function(service) {
|
| + return service.getCharacteristic(nonIncludedCharacteristicUUID);
|
| + }).then(function(characteristic) {
|
| + assert_equals(characteristic, null,
|
| + "Non existent characteristic should return null.");
|
| + });
|
| +}, 'Request for wrong characteristic. Should return null.');
|
| +
|
| +sequential_promise_test(function() {
|
| + testRunner.setBluetoothMockDataSet('ConnectableDeviceAdapter');
|
| + return navigator.bluetooth.requestDevice().then(function(device) {
|
| + return device.connectGATT();
|
| + }).then(function(gattServer) {
|
| + return gattServer.getPrimaryService(serviceUUID);
|
| + }).then(function(service) {
|
| + return service.getCharacteristic(includedCharacteristicUUID);
|
| + }).then(function(characteristic) {
|
| + assert_equals(characteristic.uuid, includedCharacteristicUUID,
|
| + "Characteristic UUID should be the same as requested UUID.");
|
| + });
|
| +}, 'Request for characteristic. Should return right characteristic');
|
| +
|
| +sequential_promise_test(function() {
|
| + testRunner.setBluetoothMockDataSet('ConnectableDeviceAdapter');
|
| + return navigator.bluetooth.requestDevice().then(function(device) {
|
| + return device.connectGATT();
|
| + }).then(function(gattServer) {
|
| + return gattServer.getPrimaryService(serviceUUID);
|
| + }).then(function(services) {
|
| + return Promise.all([services.getCharacteristic(includedCharacteristicUUID),
|
| + services.getCharacteristic(includedCharacteristicUUID)]);
|
| + }).then(function(characteristics) {
|
| + // TODO(ortuno): getCharacteristic should return the same object
|
| + // if it was created earlier.
|
| + // https://crbug.com/495270
|
| + assert_not_equals(characteristics[0], characteristics[1],
|
| + "Should return the same service as the first call.");
|
| + });
|
| +}, 'Calls to get the same characteristic should return the same object.');
|
| +
|
| +</script>
|
|
|