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) {
......
......@@ -278,6 +278,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetServices) {
// Load and wait for setup.
ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("bluetooth_low_energy/get_services")));
EXPECT_TRUE(listener.WaitUntilSatisfied());
......@@ -306,6 +307,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetService) {
// Load and wait for setup.
ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("bluetooth_low_energy/get_service")));
EXPECT_TRUE(listener.WaitUntilSatisfied());
......@@ -323,7 +325,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ServiceEvents) {
catcher.RestrictToBrowserContext(browser()->profile());
// Load the extension and let it set up.
ExtensionTestMessageListener listener("ready", true);
ExtensionTestMessageListener listener(true);
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("bluetooth_low_energy/service_events")));
......@@ -347,6 +349,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ServiceEvents) {
mock_adapter_, device0_.get(), service0_.get());
EXPECT_TRUE(listener.WaitUntilSatisfied());
ASSERT_EQ("ready", listener.message()) << listener.message();
listener.Reply("go");
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
......@@ -375,9 +378,10 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedService) {
event_router()->GattDiscoveryCompleteForService(mock_adapter_,
service0_.get());
ExtensionTestMessageListener get_service_success_listener("getServiceSuccess",
true);
ExtensionTestMessageListener get_service_success_listener(true);
EXPECT_TRUE(get_service_success_listener.WaitUntilSatisfied());
ASSERT_EQ("getServiceSuccess", get_service_success_listener.message())
<< get_service_success_listener.message();
testing::Mock::VerifyAndClearExpectations(mock_adapter_);
testing::Mock::VerifyAndClearExpectations(device0_.get());
......@@ -388,9 +392,10 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedService) {
event_router()->GattServiceRemoved(
mock_adapter_, device0_.get(), service0_.get());
ExtensionTestMessageListener get_service_fail_listener("getServiceFail",
true);
ExtensionTestMessageListener get_service_fail_listener(true);
EXPECT_TRUE(get_service_fail_listener.WaitUntilSatisfied());
ASSERT_EQ("getServiceFail", get_service_fail_listener.message())
<< get_service_fail_listener.message();
testing::Mock::VerifyAndClearExpectations(mock_adapter_);
testing::Mock::VerifyAndClearExpectations(device0_.get());
......@@ -408,6 +413,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetIncludedServices) {
// Wait for initial call to end with failure as there is no mapping.
ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
EXPECT_TRUE(listener.WaitUntilSatisfied());
// Set up for the rest of the calls before replying. Included services can be
......@@ -500,6 +506,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetCharacteristic) {
// Load the extension and wait for first test.
ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("bluetooth_low_energy/get_characteristic")));
EXPECT_TRUE(listener.WaitUntilSatisfied());
......@@ -560,6 +567,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, CharacteristicProperties) {
BluetoothGattCharacteristic::kPropertyWritableAuxiliaries));
ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/characteristic_properties")));
EXPECT_TRUE(listener.WaitUntilSatisfied());
......@@ -594,8 +602,9 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedCharacteristic) {
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/get_removed_characteristic")));
ExtensionTestMessageListener listener("ready", true);
ExtensionTestMessageListener listener(true);
EXPECT_TRUE(listener.WaitUntilSatisfied());
ASSERT_EQ("ready", listener.message()) << listener.message();
testing::Mock::VerifyAndClearExpectations(mock_adapter_);
testing::Mock::VerifyAndClearExpectations(device0_.get());
testing::Mock::VerifyAndClearExpectations(service0_.get());
......@@ -609,6 +618,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedCharacteristic) {
listener.Reply("go");
listener.Reset();
EXPECT_TRUE(listener.WaitUntilSatisfied());
ASSERT_EQ("ready", listener.message()) << listener.message();
listener.Reply("go");
......@@ -713,9 +723,10 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReadCharacteristicValue) {
.WillOnce(InvokeCallbackArgument<0>(value));
ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/read_characteristic_value")));
EXPECT_TRUE(listener.WaitUntilSatisfied());
listener.WaitUntilSatisfied();
listener.Reply("go");
......@@ -755,6 +766,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, WriteCharacteristicValue) {
EXPECT_CALL(*chrc0_, GetValue()).Times(1).WillOnce(ReturnRef(write_value));
ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/write_characteristic_value")));
EXPECT_TRUE(listener.WaitUntilSatisfied());
......@@ -796,6 +808,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetDescriptors) {
.WillOnce(Return(descriptors));
ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("bluetooth_low_energy/get_descriptors")));
EXPECT_TRUE(listener.WaitUntilSatisfied());
......@@ -840,6 +853,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetDescriptor) {
// Load the extension and wait for first test.
ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("bluetooth_low_energy/get_descriptor")));
EXPECT_TRUE(listener.WaitUntilSatisfied());
......@@ -879,8 +893,9 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedDescriptor) {
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/get_removed_descriptor")));
ExtensionTestMessageListener listener("ready", true);
ExtensionTestMessageListener listener(true);
EXPECT_TRUE(listener.WaitUntilSatisfied());
ASSERT_EQ("ready", listener.message()) << listener.message();
testing::Mock::VerifyAndClearExpectations(mock_adapter_);
testing::Mock::VerifyAndClearExpectations(device0_.get());
testing::Mock::VerifyAndClearExpectations(service0_.get());
......@@ -896,6 +911,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedDescriptor) {
listener.Reply("go");
listener.Reset();
EXPECT_TRUE(listener.WaitUntilSatisfied());
ASSERT_EQ("ready", listener.message()) << listener.message();
listener.Reply("go");
......@@ -970,6 +986,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReadDescriptorValue) {
.WillOnce(InvokeCallbackArgument<0>(value));
ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/read_descriptor_value")));
EXPECT_TRUE(listener.WaitUntilSatisfied());
......@@ -1018,6 +1035,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, WriteDescriptorValue) {
EXPECT_CALL(*desc0_, GetValue()).Times(1).WillOnce(ReturnRef(write_value));
ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/write_descriptor_value")));
EXPECT_TRUE(listener.WaitUntilSatisfied());
......@@ -1077,7 +1095,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, UuidPermissionEvents) {
ResultCatcher catcher;
catcher.RestrictToBrowserContext(browser()->profile());
ExtensionTestMessageListener listener("ready", true);
ExtensionTestMessageListener listener(true);
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/uuid_permission_events")));
......@@ -1097,6 +1115,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, UuidPermissionEvents) {
EXPECT_TRUE(listener.WaitUntilSatisfied());
listener.Reply("go");
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
ASSERT_EQ("ready", listener.message()) << listener.message();
event_router()->GattDescriptorRemoved(mock_adapter_, desc0_.get());
event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get());
......@@ -1184,15 +1203,17 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ConnectInProgress) {
.Times(1)
.WillOnce(SaveArg<0>(&connect_callback));
ExtensionTestMessageListener listener("ready", true);
ExtensionTestMessageListener listener(true);
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/connect_in_progress")));
listener.WaitUntilSatisfied();
EXPECT_TRUE(listener.WaitUntilSatisfied());
ASSERT_EQ("ready", listener.message()) << listener.message();
connect_callback.Run(conn_ptr.Pass());
listener.Reset();
listener.WaitUntilSatisfied();
EXPECT_TRUE(listener.WaitUntilSatisfied());
ASSERT_EQ("ready", listener.message()) << listener.message();
disconnect_callback.Run();
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
......@@ -1250,6 +1271,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, StartStopNotifications) {
session1));
ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/start_stop_notifications")));
......
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