Commit 5f71564c authored by jamuraa's avatar jamuraa Committed by Commit bot

Short-circuit failures in BLE js tests

Use chrome.test.sendMessage instead of chrome.test.fail so we
short-circuit instead of timeout on javascript failures where we're
waiting for a go signal.

BUG=388958
R=armansito@chromium.org

Review URL: https://codereview.chromium.org/593163002

Cr-Commit-Position: refs/heads/master@{#297292}
parent a8741d03
......@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var error;
function testCharacteristicProperties() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertEq(requestCount, characteristics.length);
for (var i = 0; i < requestCount; i++) {
......@@ -43,14 +49,21 @@ function compareProperties(a, b) {
}
function failOnError() {
if (error !== undefined)
return true;
if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message);
error = 'Unexpected error: ' + chrome.runtime.lastError.message;
chrome.test.runTests([testCharacteristicProperties]);
}
return false;
}
for (var i = 0; i < requestCount; i++) {
chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) {
failOnError();
if (failOnError())
return;
characteristics.push(result);
if (characteristics.length == requestCount) {
......
......@@ -10,12 +10,14 @@ var errorInProgress = 'In progress';
function expectError(message) {
if (!chrome.runtime.lastError ||
chrome.runtime.lastError.message != message)
chrome.test.fail('Expected error: ' + message);
chrome.test.sendMessage('Expected error: <' + message + '> got <'
+ chrome.runtime.lastError.message + '>');
}
function expectSuccess() {
if (chrome.runtime.lastError)
chrome.test.fail('Unexpected error: ' + chrome.runtime.lastError.message);
chrome.test.sendMessage('Unexpected error: '
+ chrome.runtime.lastError.message);
}
ble.connect(deviceAddress0, function () {
......
......@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var error;
function testGetCharacteristic() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertTrue(characteristic != null,
'Characteristic is null.');
chrome.test.assertEq('char_id0', characteristic.instanceId);
......@@ -38,35 +44,41 @@ var badCharId = 'char_id1';
var characteristic = null;
// 1. Unknown characteristic instanceId.
chrome.bluetoothLowEnergy.getCharacteristic(badCharId, function (result) {
function expectFailed(result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('getCharacteristics should have failed');
error = 'getCharacteristic call should have failed';
chrome.test.runTests([testGetCharacteristic]);
return false;
}
return true;
}
// 1. Unknown characteristic instanceId.
chrome.bluetoothLowEnergy.getCharacteristic(badCharId, function (result) {
if (!expectFailed(result))
return;
// 2. Known characteristic instanceId, but the mapped device is unknown.
chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('getCharacteristics should have failed');
}
if (!expectFailed(result))
return;
// 3. Known characteristic instanceId, but the mapped service is unknown.
chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('getCharacteristics should have failed');
}
if (!expectFailed(result))
return;
// 4. Known characteristic instanceId, but the mapped service does not
// know about the characteristic.
chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('getCharacteristics should have failed');
}
if (!expectFailed(result))
return;
// 5. Success.
chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) {
if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message);
error = 'Unexpected error: ' + chrome.runtime.lastError.message;
chrome.test.runTests([testGetCharacteristic]);
}
characteristic = result;
......
......@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var error;
function testGetCharacteristics() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertEq(2, chrcs.length);
chrome.test.assertEq('char_id0', chrcs[0].instanceId);
......@@ -52,25 +58,37 @@ function testGetCharacteristics() {
var serviceId = 'service_id0';
var chrcs = null;
function failOnError() {
function earlyError(message) {
error = message;
chrome.test.runTests([testGetCharacteristics]);
}
function expectSuccess() {
if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message);
earlyError('Unexpected Error: ' + chrome.runtime.lastError.message);
}
return error !== undefined;
}
chrome.bluetoothLowEnergy.getCharacteristics(serviceId, function (result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('getCharacteristics should have failed.');
earlyError('getCharacteristics should have failed.');
return;
}
chrome.bluetoothLowEnergy.getCharacteristics(serviceId, function (result) {
failOnError();
if (expectSuccess())
return;
if (!result || result.length != 0) {
chrome.test.fail('Characteristics should be empty.');
earlyError('Characteristics should be empty.');
return;
}
chrome.bluetoothLowEnergy.getCharacteristics(serviceId, function (result) {
failOnError();
if (expectSuccess())
return;
chrcs = result;
chrome.test.sendMessage('ready', function (message) {
......
......@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var error;
function testGetDescriptor() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertTrue(descriptor != null, '\'descriptor\' is null');
chrome.test.assertEq('desc_id0', descriptor.instanceId);
......@@ -27,42 +33,52 @@ var badDescId = 'desc_id1';
var descriptor = null;
function earlyError(message) {
error = message;
chrome.test.runTests([testGetDescriptor]);
}
function expectError(result) {
if (result || !chrome.runtime.lastError) {
earlyError('getDescriptor should have failed');
}
return error !== undefined;
}
// 1. Unknown descriptor instanceId.
getDescriptor(badDescId, function (result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('getDescriptor should have failed for \'badDescId\'');
earlyError('getDescriptor should have failed for \'badDescId\'');
return;
}
// 2. Known descriptor instanceId, but the mapped device is unknown.
getDescriptor(descId, function (result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('getDescriptor should have failed');
}
if (expectError(result))
return;
// 3. Known descriptor instanceId, but the mapped service is unknown.
getDescriptor(descId, function (result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('getDescriptor should have failed');
}
if (expectError(result))
return;
// 4. Known descriptor instanceId, but the mapped characteristic is
// unknown.
getDescriptor(descId, function (result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('getDescriptor should have failed');
}
if (expectError(result))
return;
// 5. Known descriptor instanceId, but the mapped the characteristic
// does not know about the descriptor.
getDescriptor(descId, function (result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('getDescriptor should have failed');
}
if (expectError(result))
return;
// 6. Success.
getDescriptor(descId, function (result) {
if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message);
earlyError(chrome.runtime.lastError.message);
return;
}
descriptor = result;
......
......@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var error;
function testGetDescriptors() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertEq(2, descrs.length);
chrome.test.assertEq('desc_id0', descrs[0].instanceId);
......@@ -35,34 +41,48 @@ var badCharId = 'char_id1';
var descrs = null;
function earlyError(message) {
error = message;
chrome.test.runTests([testGetDescriptors]);
}
function failOnError() {
if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message);
earlyError(chrome.runtime.lastError.message);
return true;
}
return false;
}
// 1. Unknown characteristic ID.
getDescriptors(badCharId, function (result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('getDescriptors should have failed for \'badCharId\'');
earlyError('getDescriptors should have failed for \'badCharId\'');
return;
}
// 2. Known ID, unknown characteristic.
getDescriptors(charId, function (result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('getDescriptors should have failed');
earlyError('getDescriptors should have failed');
return;
}
// 3. Empty descriptors.
getDescriptors(charId, function (result) {
failOnError();
if (failOnError())
return;
if (!result || result.length != 0) {
chrome.test.fail('Descriptors should be empty');
earlyError('Descriptors should be empty');
return;
}
// 4. Success.
getDescriptors(charId, function (result) {
failOnError();
if (failOnError())
return;
descrs = result;
chrome.test.sendMessage('ready', function (message) {
......
......@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var error;
function testGetIncludedServices() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertTrue(services != null, '\'services\' is null');
chrome.test.assertEq(1, services.length);
chrome.test.assertEq(includedId, services[0].instanceId);
......@@ -14,34 +20,47 @@ var serviceId = 'service_id0';
var includedId = 'service_id1';
var services = null;
function earlyError(message) {
error = message;
chrome.test.runTests([testGetIncludedServices]);
}
function failOnError() {
if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message);
earlyError(chrome.runtime.lastError.message);
return true;
}
return false;
}
chrome.bluetoothLowEnergy.getIncludedServices(serviceId, function (result) {
// No mapping for |serviceId|.
if (result || !chrome.runtime.lastError) {
chrome.test.fail('getIncludedServices should have failed');
earlyError('getIncludedServices should have failed');
return;
}
chrome.test.sendMessage('ready', function (message) {
chrome.bluetoothLowEnergy.getIncludedServices(serviceId, function (result) {
failOnError();
if (failOnError())
return;
if (!result || result.length != 0) {
chrome.test.fail('Included services should be empty.');
earlyError('Included services should be empty.');
return;
}
chrome.bluetoothLowEnergy.getIncludedServices(serviceId,
function (result) {
failOnError();
if (failOnError())
return;
services = result;
chrome.test.sendMessage('ready', function (message) {
chrome.test.runTests([testGetIncludedServices]);
});
});
});
});
});
});
......@@ -7,7 +7,7 @@ var charId = 'char_id0';
getCharacteristic(charId, function (result) {
if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message);
chrome.test.sendMessage(chrome.runtime.lastError.message);
}
chrome.test.assertEq(charId, result.instanceId);
......@@ -15,7 +15,7 @@ getCharacteristic(charId, function (result) {
chrome.test.sendMessage('ready', function (message) {
getCharacteristic(charId, function (result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('Call to getCharacteristic should have failed');
chrome.test.sendMessage('Call to getCharacteristic should have failed');
}
chrome.test.sendMessage('ready', function (message) {
......
......@@ -7,7 +7,7 @@ var descId = 'desc_id0';
getDescriptor(descId, function (result) {
if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message);
chrome.test.sendMessage(chrome.runtime.lastError.message);
}
chrome.test.assertEq(descId, result.instanceId);
......@@ -15,7 +15,7 @@ getDescriptor(descId, function (result) {
chrome.test.sendMessage('ready', function (message) {
getDescriptor(descId, function (result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('Call to getDescriptor should have failed');
chrome.test.sendMessage('Call to getDescriptor should have failed');
}
chrome.test.sendMessage('ready', function (message) {
......
......@@ -6,7 +6,7 @@ chrome.bluetoothLowEnergy.onServiceAdded.addListener(function (result) {
// getService should return this service.
chrome.bluetoothLowEnergy.getService(result.instanceId, function (service) {
if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message);
chrome.test.sendMessage(chrome.runtime.lastError.message);
}
chrome.test.assertEq(result.instanceId, service.instanceId);
......@@ -19,7 +19,7 @@ chrome.bluetoothLowEnergy.onServiceRemoved.addListener(function (result) {
// getService should return error.
chrome.bluetoothLowEnergy.getService(result.instanceId, function (service) {
if (service || !chrome.runtime.lastError) {
chrome.test.fail('Call to getService should have failed.');
chrome.test.sendMessage('Call to getService should have failed.');
}
chrome.test.sendMessage('getServiceFail', function (message) {
......
......@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var error;
function testGetService() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertTrue(service != null);
chrome.test.assertEq(serviceId, service.instanceId);
......@@ -20,34 +26,48 @@ var badServiceId = 'service_id1';
var service = null;
function earlyError(message) {
error = message;
chrome.test.runTests([testGetService]);
}
function failOnError() {
if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message);
earlyError(chrome.runtime.lastError.message);
return true;
}
return false;
}
// 1. Unknown service instanceId.
chrome.bluetoothLowEnergy.getService(badServiceId, function(result) {
function failOnSuccess(result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('Unexpected service.');
earlyError('Unexpected service.');
return true;
}
return false;
}
// 1. Unknown service instanceId.
chrome.bluetoothLowEnergy.getService(badServiceId, function(result) {
if (failOnSuccess(result))
return;
// 2. Known service instanceId, but the mapped device is unknown.
chrome.bluetoothLowEnergy.getService(serviceId, function(result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('Unexpected service.');
}
if (failOnSuccess(result))
return;
// 3. Known service instanceId, but the mapped device does not know about
// the service.
chrome.bluetoothLowEnergy.getService(serviceId, function(result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('Unexpected service.');
}
if (failOnSuccess(result))
return;
// 4. Success.
chrome.bluetoothLowEnergy.getService(serviceId, function(result) {
failOnError();
if (failOnError())
return;
service = result;
chrome.test.sendMessage('ready', function(message) {
......
......@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var error;
function testGetServices() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertEq(2, services.length);
chrome.test.assertEq('service_id0', services[0].instanceId);
......@@ -25,25 +31,38 @@ function testGetServices() {
var deviceAddress = '11:22:33:44:55:66';
var services = null;
function earlyError(message) {
error = message;
chrome.test.runTests([testGetServices]);
}
function failOnError() {
if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message);
earlyError(chrome.runtime.lastError.message);
return true;
}
return false;
}
chrome.bluetoothLowEnergy.getServices(deviceAddress, function(result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('Unexpected device.');
earlyError('Unexpected device.');
return;
}
chrome.bluetoothLowEnergy.getServices(deviceAddress, function(result) {
failOnError();
if (failOnError())
return;
if (!result || result.length != 0) {
chrome.test.fail('Services should be empty.');
earlyError('Services should be empty.');
return;
}
chrome.bluetoothLowEnergy.getServices(deviceAddress, function(result) {
failOnError();
if (failOnError())
return;
services = result;
chrome.test.sendMessage('ready', function(message) {
......
......@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var error;
function testReadCharacteristicValue() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertTrue(characteristic != null, '\'characteristic\' is null');
chrome.test.assertEq(charId, characteristic.instanceId);
......@@ -15,29 +21,39 @@ var badCharId = 'char_id1';
var characteristic = null;
function earlyError(message) {
error = message;
chrome.test.runTests([testReadCharacteristicValue]);
}
// 1. Unknown characteristic instanceId.
readCharacteristicValue(badCharId, function (result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('\'badCharId\' did not cause failure');
earlyError('\'badCharId\' did not cause failure');
return;
}
// 2. Known characteristic instanceId, but call failure.
readCharacteristicValue(charId, function (result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('readCharacteristicValue should have failed');
earlyError('readCharacteristicValue should have failed');
return;
}
// 3. Call should succeed.
readCharacteristicValue(charId, function (result) {
if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message);
earlyError(chrome.runtime.lastError.message);
return;
}
characteristic = result;
chrome.test.sendMessage('ready', function (message) {
chrome.test.sendMessage('ready', function (reply) {
chrome.test.runTests([testReadCharacteristicValue]);
});
});
});
});
......@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var error;
function testReadDescriptorValue() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertTrue(descriptor != null, '\'descriptor\' is null');
chrome.test.assertEq(descId, descriptor.instanceId);
......@@ -15,22 +21,30 @@ var badDescId = 'desc_id1';
var descriptor = null;
function earlyError(message) {
error = message;
chrome.test.runTests([testReadDescriptorValue]);
}
// 1. Unknown descriptor instanceId.
readDescriptorValue(badDescId, function (result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('\'badDescId\' did not cause failure');
earlyError('\'badDescId\' did not cause failure');
return;
}
// 2. Known descriptor instanceId, but call failure.
readDescriptorValue(descId, function (result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('readDescriptorValue should have failed');
earlyError('readDescriptorValue should have failed');
return;
}
// 3. Call should succeed.
readDescriptorValue(descId, function (result) {
if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message);
earlyError(chrome.runtime.lastError.message);
return;
}
descriptor = result;
......
......@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var error;
function testStartStopNotifications() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertEq(1, Object.keys(changedChrcs).length);
chrome.test.assertEq(charId0, changedChrcs[charId0].instanceId);
chrome.test.succeed();
......@@ -23,33 +29,27 @@ var ble = chrome.bluetoothLowEnergy;
var start = ble.startCharacteristicNotifications;
var stop = ble.stopCharacteristicNotifications;
function sendReady(errorMessage) {
chrome.test.sendMessage('ready', function (message) {
if (errorMessage) {
chrome.test.fail(errorMessage);
return;
}
chrome.test.runTests([testStartStopNotifications]);
});
function earlyError(message) {
error = message;
chrome.test.runTests([testStartStopNotifications]);
}
function expectError(expectedMessage) {
if (!chrome.runtime.lastError) {
sendReady('Expected error: ' + expectedMessage);
return;
}
if (chrome.runtime.lastError.message != expectedMessage) {
sendReady('Expected error: ' + expectedMessage + ', got error: ' +
expectedMessage);
earlyError('Expected error: ' + expectedMessage);
} else if (chrome.runtime.lastError.message != expectedMessage) {
earlyError('Expected error: ' + expectedMessage + ', got error: ' +
expectedMessage);
}
return error !== undefined;
}
function expectSuccess() {
if (chrome.runtime.lastError) {
sendReady('Unexpected error: ' + chrome.runtime.lastError.message);
earlyError('Unexpected error: ' + chrome.runtime.lastError.message);
}
return error !== undefined;
}
ble.onCharacteristicValueChanged.addListener(function (chrc) {
......@@ -57,26 +57,48 @@ ble.onCharacteristicValueChanged.addListener(function (chrc) {
});
start('foo', function () {
expectError(errorNotFound);
if (expectError(errorNotFound))
return;
start(charId2, function () {
expectError(errorPermissionDenied);
if (expectError(errorPermissionDenied))
return;
stop(charId0, function () {
expectError(errorNotNotifying);
if (expectError(errorNotNotifying))
return;
start(charId0, function () {
expectError(errorOperationFailed);
if (expectError(errorOperationFailed))
return;
start(charId0, function () {
expectSuccess();
if (expectSuccess())
return;
start(charId0, function () {
expectError(errorAlreadyNotifying);
if (expectError(errorAlreadyNotifying))
return;
start(charId1, function () {
expectSuccess();
if (expectSuccess())
return;
stop(charId1, function () {
expectSuccess();
if (expectSuccess())
return;
stop(charId1, function () {
expectError(errorNotNotifying);
if (expectError(errorNotNotifying))
return;
stop(charId2, function () {
expectError(errorNotNotifying);
sendReady(undefined);
if (expectError(errorNotNotifying))
return;
chrome.test.sendMessage('ready', function (message) {
chrome.test.runTests([testStartStopNotifications]);
});
});
});
});
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function listener(data) {
chrome.test.fail('Event should not have been received.');
chrome.test.sendMessage('Event should not have been received.');
}
chrome.bluetoothLowEnergy.onServiceChanged.addListener(listener);
......
......@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var error;
function testWriteCharacteristicValue() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertTrue(characteristic != null, '\'characteristic\' is null');
chrome.test.assertEq(charId, characteristic.instanceId);
......@@ -29,22 +35,30 @@ var writeValue = new ArrayBuffer(bytes.length);
var valueBytes = new Uint8Array(writeValue);
valueBytes.set(bytes);
function earlyError(message) {
error = message;
chrome.test.runTests([testWriteCharacteristicValue]);
}
// 1. Unknown characteristic instanceId.
writeCharacteristicValue(badCharId, writeValue, function (result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('\'badCharId\' did not cause failure');
earlyError('\'badCharId\' did not cause failure');
return;
}
// 2. Known characteristic instanceId, but call failure.
writeCharacteristicValue(charId, writeValue, function (result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('writeCharacteristicValue should have failed');
earlyError('writeCharacteristicValue should have failed');
return;
}
// 3. Call should succeed.
writeCharacteristicValue(charId, writeValue, function (result) {
if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message);
earlyError(chrome.runtime.lastError.message);
return;
}
chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) {
......
......@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var error;
function testWriteDescriptorValue() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertTrue(descriptor != null, '\'descriptor\' is null');
chrome.test.assertEq(descId, descriptor.instanceId);
......@@ -16,6 +22,11 @@ function testWriteDescriptorValue() {
chrome.test.succeed();
}
function earlyError(message) {
error = message;
chrome.test.runTests([testWriteDescriptorValue]);
}
var writeDescriptorValue = chrome.bluetoothLowEnergy.writeDescriptorValue;
var descId = 'desc_id0';
var badDescId = 'desc_id1';
......@@ -30,19 +41,22 @@ valueBytes.set(bytes);
// 1. Unknown descriptor instanceId.
writeDescriptorValue(badDescId, writeValue, function (result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('\'badDescId\' did not cause failure');
earlyError('\'badDescId\' did not cause failure');
return;
}
// 2. Known descriptor instanceId, but call failure.
writeDescriptorValue(descId, writeValue, function (result) {
if (result || !chrome.runtime.lastError) {
chrome.test.fail('writeDescriptorValue should have failed');
earlyError('writeDescriptorValue should have failed');
return;
}
// 3. Call should succeed.
writeDescriptorValue(descId, writeValue, function (result) {
if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message);
earlyError(chrome.runtime.lastError.message);
return;
}
chrome.bluetoothLowEnergy.getDescriptor(descId, function (result) {
......
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