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 @@ ...@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
var error;
function testCharacteristicProperties() { function testCharacteristicProperties() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertEq(requestCount, characteristics.length); chrome.test.assertEq(requestCount, characteristics.length);
for (var i = 0; i < requestCount; i++) { for (var i = 0; i < requestCount; i++) {
...@@ -43,14 +49,21 @@ function compareProperties(a, b) { ...@@ -43,14 +49,21 @@ function compareProperties(a, b) {
} }
function failOnError() { function failOnError() {
if (error !== undefined)
return true;
if (chrome.runtime.lastError) { 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++) { for (var i = 0; i < requestCount; i++) {
chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) { chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) {
failOnError(); if (failOnError())
return;
characteristics.push(result); characteristics.push(result);
if (characteristics.length == requestCount) { if (characteristics.length == requestCount) {
......
...@@ -10,12 +10,14 @@ var errorInProgress = 'In progress'; ...@@ -10,12 +10,14 @@ var errorInProgress = 'In progress';
function expectError(message) { function expectError(message) {
if (!chrome.runtime.lastError || if (!chrome.runtime.lastError ||
chrome.runtime.lastError.message != message) chrome.runtime.lastError.message != message)
chrome.test.fail('Expected error: ' + message); chrome.test.sendMessage('Expected error: <' + message + '> got <'
+ chrome.runtime.lastError.message + '>');
} }
function expectSuccess() { function expectSuccess() {
if (chrome.runtime.lastError) 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 () { ble.connect(deviceAddress0, function () {
......
...@@ -2,7 +2,13 @@ ...@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
var error;
function testGetCharacteristic() { function testGetCharacteristic() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertTrue(characteristic != null, chrome.test.assertTrue(characteristic != null,
'Characteristic is null.'); 'Characteristic is null.');
chrome.test.assertEq('char_id0', characteristic.instanceId); chrome.test.assertEq('char_id0', characteristic.instanceId);
...@@ -38,35 +44,41 @@ var badCharId = 'char_id1'; ...@@ -38,35 +44,41 @@ var badCharId = 'char_id1';
var characteristic = null; var characteristic = null;
// 1. Unknown characteristic instanceId. function expectFailed(result) {
chrome.bluetoothLowEnergy.getCharacteristic(badCharId, function (result) {
if (result || !chrome.runtime.lastError) { 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. // 2. Known characteristic instanceId, but the mapped device is unknown.
chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) { chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) {
if (result || !chrome.runtime.lastError) { if (!expectFailed(result))
chrome.test.fail('getCharacteristics should have failed'); return;
}
// 3. Known characteristic instanceId, but the mapped service is unknown. // 3. Known characteristic instanceId, but the mapped service is unknown.
chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) { chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) {
if (result || !chrome.runtime.lastError) { if (!expectFailed(result))
chrome.test.fail('getCharacteristics should have failed'); return;
}
// 4. Known characteristic instanceId, but the mapped service does not // 4. Known characteristic instanceId, but the mapped service does not
// know about the characteristic. // know about the characteristic.
chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) { chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) {
if (result || !chrome.runtime.lastError) { if (!expectFailed(result))
chrome.test.fail('getCharacteristics should have failed'); return;
}
// 5. Success. // 5. Success.
chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) { chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) {
if (chrome.runtime.lastError) { if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message); error = 'Unexpected error: ' + chrome.runtime.lastError.message;
chrome.test.runTests([testGetCharacteristic]);
} }
characteristic = result; characteristic = result;
......
...@@ -2,7 +2,13 @@ ...@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
var error;
function testGetCharacteristics() { function testGetCharacteristics() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertEq(2, chrcs.length); chrome.test.assertEq(2, chrcs.length);
chrome.test.assertEq('char_id0', chrcs[0].instanceId); chrome.test.assertEq('char_id0', chrcs[0].instanceId);
...@@ -52,25 +58,37 @@ function testGetCharacteristics() { ...@@ -52,25 +58,37 @@ function testGetCharacteristics() {
var serviceId = 'service_id0'; var serviceId = 'service_id0';
var chrcs = null; var chrcs = null;
function failOnError() { function earlyError(message) {
error = message;
chrome.test.runTests([testGetCharacteristics]);
}
function expectSuccess() {
if (chrome.runtime.lastError) { 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) { chrome.bluetoothLowEnergy.getCharacteristics(serviceId, function (result) {
if (result || !chrome.runtime.lastError) { if (result || !chrome.runtime.lastError) {
chrome.test.fail('getCharacteristics should have failed.'); earlyError('getCharacteristics should have failed.');
return;
} }
chrome.bluetoothLowEnergy.getCharacteristics(serviceId, function (result) { chrome.bluetoothLowEnergy.getCharacteristics(serviceId, function (result) {
failOnError(); if (expectSuccess())
return;
if (!result || result.length != 0) { if (!result || result.length != 0) {
chrome.test.fail('Characteristics should be empty.'); earlyError('Characteristics should be empty.');
return;
} }
chrome.bluetoothLowEnergy.getCharacteristics(serviceId, function (result) { chrome.bluetoothLowEnergy.getCharacteristics(serviceId, function (result) {
failOnError(); if (expectSuccess())
return;
chrcs = result; chrcs = result;
chrome.test.sendMessage('ready', function (message) { chrome.test.sendMessage('ready', function (message) {
......
...@@ -2,7 +2,13 @@ ...@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
var error;
function testGetDescriptor() { function testGetDescriptor() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertTrue(descriptor != null, '\'descriptor\' is null'); chrome.test.assertTrue(descriptor != null, '\'descriptor\' is null');
chrome.test.assertEq('desc_id0', descriptor.instanceId); chrome.test.assertEq('desc_id0', descriptor.instanceId);
...@@ -27,42 +33,52 @@ var badDescId = 'desc_id1'; ...@@ -27,42 +33,52 @@ var badDescId = 'desc_id1';
var descriptor = null; 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. // 1. Unknown descriptor instanceId.
getDescriptor(badDescId, function (result) { getDescriptor(badDescId, function (result) {
if (result || !chrome.runtime.lastError) { 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. // 2. Known descriptor instanceId, but the mapped device is unknown.
getDescriptor(descId, function (result) { getDescriptor(descId, function (result) {
if (result || !chrome.runtime.lastError) { if (expectError(result))
chrome.test.fail('getDescriptor should have failed'); return;
}
// 3. Known descriptor instanceId, but the mapped service is unknown. // 3. Known descriptor instanceId, but the mapped service is unknown.
getDescriptor(descId, function (result) { getDescriptor(descId, function (result) {
if (result || !chrome.runtime.lastError) { if (expectError(result))
chrome.test.fail('getDescriptor should have failed'); return;
}
// 4. Known descriptor instanceId, but the mapped characteristic is // 4. Known descriptor instanceId, but the mapped characteristic is
// unknown. // unknown.
getDescriptor(descId, function (result) { getDescriptor(descId, function (result) {
if (result || !chrome.runtime.lastError) { if (expectError(result))
chrome.test.fail('getDescriptor should have failed'); return;
}
// 5. Known descriptor instanceId, but the mapped the characteristic // 5. Known descriptor instanceId, but the mapped the characteristic
// does not know about the descriptor. // does not know about the descriptor.
getDescriptor(descId, function (result) { getDescriptor(descId, function (result) {
if (result || !chrome.runtime.lastError) { if (expectError(result))
chrome.test.fail('getDescriptor should have failed'); return;
}
// 6. Success. // 6. Success.
getDescriptor(descId, function (result) { getDescriptor(descId, function (result) {
if (chrome.runtime.lastError) { if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message); earlyError(chrome.runtime.lastError.message);
return;
} }
descriptor = result; descriptor = result;
......
...@@ -2,7 +2,13 @@ ...@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
var error;
function testGetDescriptors() { function testGetDescriptors() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertEq(2, descrs.length); chrome.test.assertEq(2, descrs.length);
chrome.test.assertEq('desc_id0', descrs[0].instanceId); chrome.test.assertEq('desc_id0', descrs[0].instanceId);
...@@ -35,34 +41,48 @@ var badCharId = 'char_id1'; ...@@ -35,34 +41,48 @@ var badCharId = 'char_id1';
var descrs = null; var descrs = null;
function earlyError(message) {
error = message;
chrome.test.runTests([testGetDescriptors]);
}
function failOnError() { function failOnError() {
if (chrome.runtime.lastError) { if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message); earlyError(chrome.runtime.lastError.message);
return true;
} }
return false;
} }
// 1. Unknown characteristic ID. // 1. Unknown characteristic ID.
getDescriptors(badCharId, function (result) { getDescriptors(badCharId, function (result) {
if (result || !chrome.runtime.lastError) { 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. // 2. Known ID, unknown characteristic.
getDescriptors(charId, function (result) { getDescriptors(charId, function (result) {
if (result || !chrome.runtime.lastError) { if (result || !chrome.runtime.lastError) {
chrome.test.fail('getDescriptors should have failed'); earlyError('getDescriptors should have failed');
return;
} }
// 3. Empty descriptors. // 3. Empty descriptors.
getDescriptors(charId, function (result) { getDescriptors(charId, function (result) {
failOnError(); if (failOnError())
return;
if (!result || result.length != 0) { if (!result || result.length != 0) {
chrome.test.fail('Descriptors should be empty'); earlyError('Descriptors should be empty');
return;
} }
// 4. Success. // 4. Success.
getDescriptors(charId, function (result) { getDescriptors(charId, function (result) {
failOnError(); if (failOnError())
return;
descrs = result; descrs = result;
chrome.test.sendMessage('ready', function (message) { chrome.test.sendMessage('ready', function (message) {
......
...@@ -2,7 +2,13 @@ ...@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
var error;
function testGetIncludedServices() { function testGetIncludedServices() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertTrue(services != null, '\'services\' is null'); chrome.test.assertTrue(services != null, '\'services\' is null');
chrome.test.assertEq(1, services.length); chrome.test.assertEq(1, services.length);
chrome.test.assertEq(includedId, services[0].instanceId); chrome.test.assertEq(includedId, services[0].instanceId);
...@@ -14,34 +20,47 @@ var serviceId = 'service_id0'; ...@@ -14,34 +20,47 @@ var serviceId = 'service_id0';
var includedId = 'service_id1'; var includedId = 'service_id1';
var services = null; var services = null;
function earlyError(message) {
error = message;
chrome.test.runTests([testGetIncludedServices]);
}
function failOnError() { function failOnError() {
if (chrome.runtime.lastError) { 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) { chrome.bluetoothLowEnergy.getIncludedServices(serviceId, function (result) {
// No mapping for |serviceId|. // No mapping for |serviceId|.
if (result || !chrome.runtime.lastError) { 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.test.sendMessage('ready', function (message) {
chrome.bluetoothLowEnergy.getIncludedServices(serviceId, function (result) { chrome.bluetoothLowEnergy.getIncludedServices(serviceId, function (result) {
failOnError(); if (failOnError())
return;
if (!result || result.length != 0) { if (!result || result.length != 0) {
chrome.test.fail('Included services should be empty.'); earlyError('Included services should be empty.');
return;
} }
chrome.bluetoothLowEnergy.getIncludedServices(serviceId, chrome.bluetoothLowEnergy.getIncludedServices(serviceId,
function (result) { function (result) {
failOnError(); if (failOnError())
return;
services = result; services = result;
chrome.test.sendMessage('ready', function (message) { chrome.test.sendMessage('ready', function (message) {
chrome.test.runTests([testGetIncludedServices]); chrome.test.runTests([testGetIncludedServices]);
}); });
}); });
}); });
}); });
}); });
...@@ -7,7 +7,7 @@ var charId = 'char_id0'; ...@@ -7,7 +7,7 @@ var charId = 'char_id0';
getCharacteristic(charId, function (result) { getCharacteristic(charId, function (result) {
if (chrome.runtime.lastError) { if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message); chrome.test.sendMessage(chrome.runtime.lastError.message);
} }
chrome.test.assertEq(charId, result.instanceId); chrome.test.assertEq(charId, result.instanceId);
...@@ -15,7 +15,7 @@ getCharacteristic(charId, function (result) { ...@@ -15,7 +15,7 @@ getCharacteristic(charId, function (result) {
chrome.test.sendMessage('ready', function (message) { chrome.test.sendMessage('ready', function (message) {
getCharacteristic(charId, function (result) { getCharacteristic(charId, function (result) {
if (result || !chrome.runtime.lastError) { 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) { chrome.test.sendMessage('ready', function (message) {
......
...@@ -7,7 +7,7 @@ var descId = 'desc_id0'; ...@@ -7,7 +7,7 @@ var descId = 'desc_id0';
getDescriptor(descId, function (result) { getDescriptor(descId, function (result) {
if (chrome.runtime.lastError) { if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message); chrome.test.sendMessage(chrome.runtime.lastError.message);
} }
chrome.test.assertEq(descId, result.instanceId); chrome.test.assertEq(descId, result.instanceId);
...@@ -15,7 +15,7 @@ getDescriptor(descId, function (result) { ...@@ -15,7 +15,7 @@ getDescriptor(descId, function (result) {
chrome.test.sendMessage('ready', function (message) { chrome.test.sendMessage('ready', function (message) {
getDescriptor(descId, function (result) { getDescriptor(descId, function (result) {
if (result || !chrome.runtime.lastError) { 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) { chrome.test.sendMessage('ready', function (message) {
......
...@@ -6,7 +6,7 @@ chrome.bluetoothLowEnergy.onServiceAdded.addListener(function (result) { ...@@ -6,7 +6,7 @@ chrome.bluetoothLowEnergy.onServiceAdded.addListener(function (result) {
// getService should return this service. // getService should return this service.
chrome.bluetoothLowEnergy.getService(result.instanceId, function (service) { chrome.bluetoothLowEnergy.getService(result.instanceId, function (service) {
if (chrome.runtime.lastError) { 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); chrome.test.assertEq(result.instanceId, service.instanceId);
...@@ -19,7 +19,7 @@ chrome.bluetoothLowEnergy.onServiceRemoved.addListener(function (result) { ...@@ -19,7 +19,7 @@ chrome.bluetoothLowEnergy.onServiceRemoved.addListener(function (result) {
// getService should return error. // getService should return error.
chrome.bluetoothLowEnergy.getService(result.instanceId, function (service) { chrome.bluetoothLowEnergy.getService(result.instanceId, function (service) {
if (service || !chrome.runtime.lastError) { 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) { chrome.test.sendMessage('getServiceFail', function (message) {
......
...@@ -2,7 +2,13 @@ ...@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
var error;
function testGetService() { function testGetService() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertTrue(service != null); chrome.test.assertTrue(service != null);
chrome.test.assertEq(serviceId, service.instanceId); chrome.test.assertEq(serviceId, service.instanceId);
...@@ -20,34 +26,48 @@ var badServiceId = 'service_id1'; ...@@ -20,34 +26,48 @@ var badServiceId = 'service_id1';
var service = null; var service = null;
function earlyError(message) {
error = message;
chrome.test.runTests([testGetService]);
}
function failOnError() { function failOnError() {
if (chrome.runtime.lastError) { if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message); earlyError(chrome.runtime.lastError.message);
return true;
} }
return false;
} }
// 1. Unknown service instanceId. function failOnSuccess(result) {
chrome.bluetoothLowEnergy.getService(badServiceId, function(result) {
if (result || !chrome.runtime.lastError) { 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. // 2. Known service instanceId, but the mapped device is unknown.
chrome.bluetoothLowEnergy.getService(serviceId, function(result) { chrome.bluetoothLowEnergy.getService(serviceId, function(result) {
if (result || !chrome.runtime.lastError) { if (failOnSuccess(result))
chrome.test.fail('Unexpected service.'); return;
}
// 3. Known service instanceId, but the mapped device does not know about // 3. Known service instanceId, but the mapped device does not know about
// the service. // the service.
chrome.bluetoothLowEnergy.getService(serviceId, function(result) { chrome.bluetoothLowEnergy.getService(serviceId, function(result) {
if (result || !chrome.runtime.lastError) { if (failOnSuccess(result))
chrome.test.fail('Unexpected service.'); return;
}
// 4. Success. // 4. Success.
chrome.bluetoothLowEnergy.getService(serviceId, function(result) { chrome.bluetoothLowEnergy.getService(serviceId, function(result) {
failOnError(); if (failOnError())
return;
service = result; service = result;
chrome.test.sendMessage('ready', function(message) { chrome.test.sendMessage('ready', function(message) {
......
...@@ -2,7 +2,13 @@ ...@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
var error;
function testGetServices() { function testGetServices() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertEq(2, services.length); chrome.test.assertEq(2, services.length);
chrome.test.assertEq('service_id0', services[0].instanceId); chrome.test.assertEq('service_id0', services[0].instanceId);
...@@ -25,25 +31,38 @@ function testGetServices() { ...@@ -25,25 +31,38 @@ function testGetServices() {
var deviceAddress = '11:22:33:44:55:66'; var deviceAddress = '11:22:33:44:55:66';
var services = null; var services = null;
function earlyError(message) {
error = message;
chrome.test.runTests([testGetServices]);
}
function failOnError() { function failOnError() {
if (chrome.runtime.lastError) { 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) { chrome.bluetoothLowEnergy.getServices(deviceAddress, function(result) {
if (result || !chrome.runtime.lastError) { if (result || !chrome.runtime.lastError) {
chrome.test.fail('Unexpected device.'); earlyError('Unexpected device.');
return;
} }
chrome.bluetoothLowEnergy.getServices(deviceAddress, function(result) { chrome.bluetoothLowEnergy.getServices(deviceAddress, function(result) {
failOnError(); if (failOnError())
return;
if (!result || result.length != 0) { if (!result || result.length != 0) {
chrome.test.fail('Services should be empty.'); earlyError('Services should be empty.');
return;
} }
chrome.bluetoothLowEnergy.getServices(deviceAddress, function(result) { chrome.bluetoothLowEnergy.getServices(deviceAddress, function(result) {
failOnError(); if (failOnError())
return;
services = result; services = result;
chrome.test.sendMessage('ready', function(message) { chrome.test.sendMessage('ready', function(message) {
......
...@@ -2,7 +2,13 @@ ...@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
var error;
function testReadCharacteristicValue() { function testReadCharacteristicValue() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertTrue(characteristic != null, '\'characteristic\' is null'); chrome.test.assertTrue(characteristic != null, '\'characteristic\' is null');
chrome.test.assertEq(charId, characteristic.instanceId); chrome.test.assertEq(charId, characteristic.instanceId);
...@@ -15,29 +21,39 @@ var badCharId = 'char_id1'; ...@@ -15,29 +21,39 @@ var badCharId = 'char_id1';
var characteristic = null; var characteristic = null;
function earlyError(message) {
error = message;
chrome.test.runTests([testReadCharacteristicValue]);
}
// 1. Unknown characteristic instanceId. // 1. Unknown characteristic instanceId.
readCharacteristicValue(badCharId, function (result) { readCharacteristicValue(badCharId, function (result) {
if (result || !chrome.runtime.lastError) { 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. // 2. Known characteristic instanceId, but call failure.
readCharacteristicValue(charId, function (result) { readCharacteristicValue(charId, function (result) {
if (result || !chrome.runtime.lastError) { if (result || !chrome.runtime.lastError) {
chrome.test.fail('readCharacteristicValue should have failed'); earlyError('readCharacteristicValue should have failed');
return;
} }
// 3. Call should succeed. // 3. Call should succeed.
readCharacteristicValue(charId, function (result) { readCharacteristicValue(charId, function (result) {
if (chrome.runtime.lastError) { if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message); earlyError(chrome.runtime.lastError.message);
return;
} }
characteristic = result; characteristic = result;
chrome.test.sendMessage('ready', function (message) { chrome.test.sendMessage('ready', function (reply) {
chrome.test.runTests([testReadCharacteristicValue]); chrome.test.runTests([testReadCharacteristicValue]);
}); });
}); });
}); });
}); });
...@@ -2,7 +2,13 @@ ...@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
var error;
function testReadDescriptorValue() { function testReadDescriptorValue() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertTrue(descriptor != null, '\'descriptor\' is null'); chrome.test.assertTrue(descriptor != null, '\'descriptor\' is null');
chrome.test.assertEq(descId, descriptor.instanceId); chrome.test.assertEq(descId, descriptor.instanceId);
...@@ -15,22 +21,30 @@ var badDescId = 'desc_id1'; ...@@ -15,22 +21,30 @@ var badDescId = 'desc_id1';
var descriptor = null; var descriptor = null;
function earlyError(message) {
error = message;
chrome.test.runTests([testReadDescriptorValue]);
}
// 1. Unknown descriptor instanceId. // 1. Unknown descriptor instanceId.
readDescriptorValue(badDescId, function (result) { readDescriptorValue(badDescId, function (result) {
if (result || !chrome.runtime.lastError) { 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. // 2. Known descriptor instanceId, but call failure.
readDescriptorValue(descId, function (result) { readDescriptorValue(descId, function (result) {
if (result || !chrome.runtime.lastError) { if (result || !chrome.runtime.lastError) {
chrome.test.fail('readDescriptorValue should have failed'); earlyError('readDescriptorValue should have failed');
return;
} }
// 3. Call should succeed. // 3. Call should succeed.
readDescriptorValue(descId, function (result) { readDescriptorValue(descId, function (result) {
if (chrome.runtime.lastError) { if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message); earlyError(chrome.runtime.lastError.message);
return;
} }
descriptor = result; descriptor = result;
......
...@@ -2,7 +2,13 @@ ...@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
var error;
function testStartStopNotifications() { function testStartStopNotifications() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertEq(1, Object.keys(changedChrcs).length); chrome.test.assertEq(1, Object.keys(changedChrcs).length);
chrome.test.assertEq(charId0, changedChrcs[charId0].instanceId); chrome.test.assertEq(charId0, changedChrcs[charId0].instanceId);
chrome.test.succeed(); chrome.test.succeed();
...@@ -23,33 +29,27 @@ var ble = chrome.bluetoothLowEnergy; ...@@ -23,33 +29,27 @@ var ble = chrome.bluetoothLowEnergy;
var start = ble.startCharacteristicNotifications; var start = ble.startCharacteristicNotifications;
var stop = ble.stopCharacteristicNotifications; 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) { function expectError(expectedMessage) {
if (!chrome.runtime.lastError) { if (!chrome.runtime.lastError) {
sendReady('Expected error: ' + expectedMessage); earlyError('Expected error: ' + expectedMessage);
return; } else if (chrome.runtime.lastError.message != expectedMessage) {
} earlyError('Expected error: ' + expectedMessage + ', got error: ' +
expectedMessage);
if (chrome.runtime.lastError.message != expectedMessage) {
sendReady('Expected error: ' + expectedMessage + ', got error: ' +
expectedMessage);
} }
return error !== undefined;
} }
function expectSuccess() { function expectSuccess() {
if (chrome.runtime.lastError) { 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) { ble.onCharacteristicValueChanged.addListener(function (chrc) {
...@@ -57,26 +57,48 @@ ble.onCharacteristicValueChanged.addListener(function (chrc) { ...@@ -57,26 +57,48 @@ ble.onCharacteristicValueChanged.addListener(function (chrc) {
}); });
start('foo', function () { start('foo', function () {
expectError(errorNotFound); if (expectError(errorNotFound))
return;
start(charId2, function () { start(charId2, function () {
expectError(errorPermissionDenied); if (expectError(errorPermissionDenied))
return;
stop(charId0, function () { stop(charId0, function () {
expectError(errorNotNotifying); if (expectError(errorNotNotifying))
return;
start(charId0, function () { start(charId0, function () {
expectError(errorOperationFailed); if (expectError(errorOperationFailed))
return;
start(charId0, function () { start(charId0, function () {
expectSuccess(); if (expectSuccess())
return;
start(charId0, function () { start(charId0, function () {
expectError(errorAlreadyNotifying); if (expectError(errorAlreadyNotifying))
return;
start(charId1, function () { start(charId1, function () {
expectSuccess(); if (expectSuccess())
return;
stop(charId1, function () { stop(charId1, function () {
expectSuccess(); if (expectSuccess())
return;
stop(charId1, function () { stop(charId1, function () {
expectError(errorNotNotifying); if (expectError(errorNotNotifying))
return;
stop(charId2, function () { stop(charId2, function () {
expectError(errorNotNotifying); if (expectError(errorNotNotifying))
sendReady(undefined); return;
chrome.test.sendMessage('ready', function (message) {
chrome.test.runTests([testStartStopNotifications]);
});
}); });
}); });
}); });
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
function listener(data) { 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); chrome.bluetoothLowEnergy.onServiceChanged.addListener(listener);
......
...@@ -2,7 +2,13 @@ ...@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
var error;
function testWriteCharacteristicValue() { function testWriteCharacteristicValue() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertTrue(characteristic != null, '\'characteristic\' is null'); chrome.test.assertTrue(characteristic != null, '\'characteristic\' is null');
chrome.test.assertEq(charId, characteristic.instanceId); chrome.test.assertEq(charId, characteristic.instanceId);
...@@ -29,22 +35,30 @@ var writeValue = new ArrayBuffer(bytes.length); ...@@ -29,22 +35,30 @@ var writeValue = new ArrayBuffer(bytes.length);
var valueBytes = new Uint8Array(writeValue); var valueBytes = new Uint8Array(writeValue);
valueBytes.set(bytes); valueBytes.set(bytes);
function earlyError(message) {
error = message;
chrome.test.runTests([testWriteCharacteristicValue]);
}
// 1. Unknown characteristic instanceId. // 1. Unknown characteristic instanceId.
writeCharacteristicValue(badCharId, writeValue, function (result) { writeCharacteristicValue(badCharId, writeValue, function (result) {
if (result || !chrome.runtime.lastError) { 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. // 2. Known characteristic instanceId, but call failure.
writeCharacteristicValue(charId, writeValue, function (result) { writeCharacteristicValue(charId, writeValue, function (result) {
if (result || !chrome.runtime.lastError) { if (result || !chrome.runtime.lastError) {
chrome.test.fail('writeCharacteristicValue should have failed'); earlyError('writeCharacteristicValue should have failed');
return;
} }
// 3. Call should succeed. // 3. Call should succeed.
writeCharacteristicValue(charId, writeValue, function (result) { writeCharacteristicValue(charId, writeValue, function (result) {
if (chrome.runtime.lastError) { if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message); earlyError(chrome.runtime.lastError.message);
return;
} }
chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) { chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) {
......
...@@ -2,7 +2,13 @@ ...@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
var error;
function testWriteDescriptorValue() { function testWriteDescriptorValue() {
if (error !== undefined) {
chrome.test.sendMessage('fail');
chrome.test.fail(error);
}
chrome.test.assertTrue(descriptor != null, '\'descriptor\' is null'); chrome.test.assertTrue(descriptor != null, '\'descriptor\' is null');
chrome.test.assertEq(descId, descriptor.instanceId); chrome.test.assertEq(descId, descriptor.instanceId);
...@@ -16,6 +22,11 @@ function testWriteDescriptorValue() { ...@@ -16,6 +22,11 @@ function testWriteDescriptorValue() {
chrome.test.succeed(); chrome.test.succeed();
} }
function earlyError(message) {
error = message;
chrome.test.runTests([testWriteDescriptorValue]);
}
var writeDescriptorValue = chrome.bluetoothLowEnergy.writeDescriptorValue; var writeDescriptorValue = chrome.bluetoothLowEnergy.writeDescriptorValue;
var descId = 'desc_id0'; var descId = 'desc_id0';
var badDescId = 'desc_id1'; var badDescId = 'desc_id1';
...@@ -30,19 +41,22 @@ valueBytes.set(bytes); ...@@ -30,19 +41,22 @@ valueBytes.set(bytes);
// 1. Unknown descriptor instanceId. // 1. Unknown descriptor instanceId.
writeDescriptorValue(badDescId, writeValue, function (result) { writeDescriptorValue(badDescId, writeValue, function (result) {
if (result || !chrome.runtime.lastError) { 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. // 2. Known descriptor instanceId, but call failure.
writeDescriptorValue(descId, writeValue, function (result) { writeDescriptorValue(descId, writeValue, function (result) {
if (result || !chrome.runtime.lastError) { if (result || !chrome.runtime.lastError) {
chrome.test.fail('writeDescriptorValue should have failed'); earlyError('writeDescriptorValue should have failed');
return;
} }
// 3. Call should succeed. // 3. Call should succeed.
writeDescriptorValue(descId, writeValue, function (result) { writeDescriptorValue(descId, writeValue, function (result) {
if (chrome.runtime.lastError) { if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message); earlyError(chrome.runtime.lastError.message);
return;
} }
chrome.bluetoothLowEnergy.getDescriptor(descId, function (result) { chrome.bluetoothLowEnergy.getDescriptor(descId, function (result) {
......
...@@ -278,6 +278,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetServices) { ...@@ -278,6 +278,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetServices) {
// Load and wait for setup. // Load and wait for setup.
ExtensionTestMessageListener listener("ready", true); ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension( ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("bluetooth_low_energy/get_services"))); test_data_dir_.AppendASCII("bluetooth_low_energy/get_services")));
EXPECT_TRUE(listener.WaitUntilSatisfied()); EXPECT_TRUE(listener.WaitUntilSatisfied());
...@@ -306,6 +307,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetService) { ...@@ -306,6 +307,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetService) {
// Load and wait for setup. // Load and wait for setup.
ExtensionTestMessageListener listener("ready", true); ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension( ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("bluetooth_low_energy/get_service"))); test_data_dir_.AppendASCII("bluetooth_low_energy/get_service")));
EXPECT_TRUE(listener.WaitUntilSatisfied()); EXPECT_TRUE(listener.WaitUntilSatisfied());
...@@ -323,7 +325,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ServiceEvents) { ...@@ -323,7 +325,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ServiceEvents) {
catcher.RestrictToBrowserContext(browser()->profile()); catcher.RestrictToBrowserContext(browser()->profile());
// Load the extension and let it set up. // Load the extension and let it set up.
ExtensionTestMessageListener listener("ready", true); ExtensionTestMessageListener listener(true);
ASSERT_TRUE(LoadExtension( ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("bluetooth_low_energy/service_events"))); test_data_dir_.AppendASCII("bluetooth_low_energy/service_events")));
...@@ -347,6 +349,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ServiceEvents) { ...@@ -347,6 +349,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ServiceEvents) {
mock_adapter_, device0_.get(), service0_.get()); mock_adapter_, device0_.get(), service0_.get());
EXPECT_TRUE(listener.WaitUntilSatisfied()); EXPECT_TRUE(listener.WaitUntilSatisfied());
ASSERT_EQ("ready", listener.message()) << listener.message();
listener.Reply("go"); listener.Reply("go");
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
...@@ -375,9 +378,10 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedService) { ...@@ -375,9 +378,10 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedService) {
event_router()->GattDiscoveryCompleteForService(mock_adapter_, event_router()->GattDiscoveryCompleteForService(mock_adapter_,
service0_.get()); service0_.get());
ExtensionTestMessageListener get_service_success_listener("getServiceSuccess", ExtensionTestMessageListener get_service_success_listener(true);
true);
EXPECT_TRUE(get_service_success_listener.WaitUntilSatisfied()); 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(mock_adapter_);
testing::Mock::VerifyAndClearExpectations(device0_.get()); testing::Mock::VerifyAndClearExpectations(device0_.get());
...@@ -388,9 +392,10 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedService) { ...@@ -388,9 +392,10 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedService) {
event_router()->GattServiceRemoved( event_router()->GattServiceRemoved(
mock_adapter_, device0_.get(), service0_.get()); mock_adapter_, device0_.get(), service0_.get());
ExtensionTestMessageListener get_service_fail_listener("getServiceFail", ExtensionTestMessageListener get_service_fail_listener(true);
true);
EXPECT_TRUE(get_service_fail_listener.WaitUntilSatisfied()); 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(mock_adapter_);
testing::Mock::VerifyAndClearExpectations(device0_.get()); testing::Mock::VerifyAndClearExpectations(device0_.get());
...@@ -408,6 +413,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetIncludedServices) { ...@@ -408,6 +413,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetIncludedServices) {
// Wait for initial call to end with failure as there is no mapping. // Wait for initial call to end with failure as there is no mapping.
ExtensionTestMessageListener listener("ready", true); ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
EXPECT_TRUE(listener.WaitUntilSatisfied()); EXPECT_TRUE(listener.WaitUntilSatisfied());
// Set up for the rest of the calls before replying. Included services can be // 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) { ...@@ -500,6 +506,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetCharacteristic) {
// Load the extension and wait for first test. // Load the extension and wait for first test.
ExtensionTestMessageListener listener("ready", true); ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension( ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("bluetooth_low_energy/get_characteristic"))); test_data_dir_.AppendASCII("bluetooth_low_energy/get_characteristic")));
EXPECT_TRUE(listener.WaitUntilSatisfied()); EXPECT_TRUE(listener.WaitUntilSatisfied());
...@@ -560,6 +567,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, CharacteristicProperties) { ...@@ -560,6 +567,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, CharacteristicProperties) {
BluetoothGattCharacteristic::kPropertyWritableAuxiliaries)); BluetoothGattCharacteristic::kPropertyWritableAuxiliaries));
ExtensionTestMessageListener listener("ready", true); ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/characteristic_properties"))); "bluetooth_low_energy/characteristic_properties")));
EXPECT_TRUE(listener.WaitUntilSatisfied()); EXPECT_TRUE(listener.WaitUntilSatisfied());
...@@ -594,8 +602,9 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedCharacteristic) { ...@@ -594,8 +602,9 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedCharacteristic) {
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/get_removed_characteristic"))); "bluetooth_low_energy/get_removed_characteristic")));
ExtensionTestMessageListener listener("ready", true); ExtensionTestMessageListener listener(true);
EXPECT_TRUE(listener.WaitUntilSatisfied()); EXPECT_TRUE(listener.WaitUntilSatisfied());
ASSERT_EQ("ready", listener.message()) << listener.message();
testing::Mock::VerifyAndClearExpectations(mock_adapter_); testing::Mock::VerifyAndClearExpectations(mock_adapter_);
testing::Mock::VerifyAndClearExpectations(device0_.get()); testing::Mock::VerifyAndClearExpectations(device0_.get());
testing::Mock::VerifyAndClearExpectations(service0_.get()); testing::Mock::VerifyAndClearExpectations(service0_.get());
...@@ -609,6 +618,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedCharacteristic) { ...@@ -609,6 +618,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedCharacteristic) {
listener.Reply("go"); listener.Reply("go");
listener.Reset(); listener.Reset();
EXPECT_TRUE(listener.WaitUntilSatisfied()); EXPECT_TRUE(listener.WaitUntilSatisfied());
ASSERT_EQ("ready", listener.message()) << listener.message();
listener.Reply("go"); listener.Reply("go");
...@@ -713,9 +723,10 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReadCharacteristicValue) { ...@@ -713,9 +723,10 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReadCharacteristicValue) {
.WillOnce(InvokeCallbackArgument<0>(value)); .WillOnce(InvokeCallbackArgument<0>(value));
ExtensionTestMessageListener listener("ready", true); ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/read_characteristic_value"))); "bluetooth_low_energy/read_characteristic_value")));
EXPECT_TRUE(listener.WaitUntilSatisfied()); listener.WaitUntilSatisfied();
listener.Reply("go"); listener.Reply("go");
...@@ -755,6 +766,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, WriteCharacteristicValue) { ...@@ -755,6 +766,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, WriteCharacteristicValue) {
EXPECT_CALL(*chrc0_, GetValue()).Times(1).WillOnce(ReturnRef(write_value)); EXPECT_CALL(*chrc0_, GetValue()).Times(1).WillOnce(ReturnRef(write_value));
ExtensionTestMessageListener listener("ready", true); ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/write_characteristic_value"))); "bluetooth_low_energy/write_characteristic_value")));
EXPECT_TRUE(listener.WaitUntilSatisfied()); EXPECT_TRUE(listener.WaitUntilSatisfied());
...@@ -796,6 +808,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetDescriptors) { ...@@ -796,6 +808,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetDescriptors) {
.WillOnce(Return(descriptors)); .WillOnce(Return(descriptors));
ExtensionTestMessageListener listener("ready", true); ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension( ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("bluetooth_low_energy/get_descriptors"))); test_data_dir_.AppendASCII("bluetooth_low_energy/get_descriptors")));
EXPECT_TRUE(listener.WaitUntilSatisfied()); EXPECT_TRUE(listener.WaitUntilSatisfied());
...@@ -840,6 +853,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetDescriptor) { ...@@ -840,6 +853,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetDescriptor) {
// Load the extension and wait for first test. // Load the extension and wait for first test.
ExtensionTestMessageListener listener("ready", true); ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension( ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("bluetooth_low_energy/get_descriptor"))); test_data_dir_.AppendASCII("bluetooth_low_energy/get_descriptor")));
EXPECT_TRUE(listener.WaitUntilSatisfied()); EXPECT_TRUE(listener.WaitUntilSatisfied());
...@@ -879,8 +893,9 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedDescriptor) { ...@@ -879,8 +893,9 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedDescriptor) {
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/get_removed_descriptor"))); "bluetooth_low_energy/get_removed_descriptor")));
ExtensionTestMessageListener listener("ready", true); ExtensionTestMessageListener listener(true);
EXPECT_TRUE(listener.WaitUntilSatisfied()); EXPECT_TRUE(listener.WaitUntilSatisfied());
ASSERT_EQ("ready", listener.message()) << listener.message();
testing::Mock::VerifyAndClearExpectations(mock_adapter_); testing::Mock::VerifyAndClearExpectations(mock_adapter_);
testing::Mock::VerifyAndClearExpectations(device0_.get()); testing::Mock::VerifyAndClearExpectations(device0_.get());
testing::Mock::VerifyAndClearExpectations(service0_.get()); testing::Mock::VerifyAndClearExpectations(service0_.get());
...@@ -896,6 +911,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedDescriptor) { ...@@ -896,6 +911,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedDescriptor) {
listener.Reply("go"); listener.Reply("go");
listener.Reset(); listener.Reset();
EXPECT_TRUE(listener.WaitUntilSatisfied()); EXPECT_TRUE(listener.WaitUntilSatisfied());
ASSERT_EQ("ready", listener.message()) << listener.message();
listener.Reply("go"); listener.Reply("go");
...@@ -970,6 +986,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReadDescriptorValue) { ...@@ -970,6 +986,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReadDescriptorValue) {
.WillOnce(InvokeCallbackArgument<0>(value)); .WillOnce(InvokeCallbackArgument<0>(value));
ExtensionTestMessageListener listener("ready", true); ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/read_descriptor_value"))); "bluetooth_low_energy/read_descriptor_value")));
EXPECT_TRUE(listener.WaitUntilSatisfied()); EXPECT_TRUE(listener.WaitUntilSatisfied());
...@@ -1018,6 +1035,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, WriteDescriptorValue) { ...@@ -1018,6 +1035,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, WriteDescriptorValue) {
EXPECT_CALL(*desc0_, GetValue()).Times(1).WillOnce(ReturnRef(write_value)); EXPECT_CALL(*desc0_, GetValue()).Times(1).WillOnce(ReturnRef(write_value));
ExtensionTestMessageListener listener("ready", true); ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/write_descriptor_value"))); "bluetooth_low_energy/write_descriptor_value")));
EXPECT_TRUE(listener.WaitUntilSatisfied()); EXPECT_TRUE(listener.WaitUntilSatisfied());
...@@ -1077,7 +1095,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, UuidPermissionEvents) { ...@@ -1077,7 +1095,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, UuidPermissionEvents) {
ResultCatcher catcher; ResultCatcher catcher;
catcher.RestrictToBrowserContext(browser()->profile()); catcher.RestrictToBrowserContext(browser()->profile());
ExtensionTestMessageListener listener("ready", true); ExtensionTestMessageListener listener(true);
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/uuid_permission_events"))); "bluetooth_low_energy/uuid_permission_events")));
...@@ -1097,6 +1115,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, UuidPermissionEvents) { ...@@ -1097,6 +1115,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, UuidPermissionEvents) {
EXPECT_TRUE(listener.WaitUntilSatisfied()); EXPECT_TRUE(listener.WaitUntilSatisfied());
listener.Reply("go"); listener.Reply("go");
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
ASSERT_EQ("ready", listener.message()) << listener.message();
event_router()->GattDescriptorRemoved(mock_adapter_, desc0_.get()); event_router()->GattDescriptorRemoved(mock_adapter_, desc0_.get());
event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get());
...@@ -1184,15 +1203,17 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ConnectInProgress) { ...@@ -1184,15 +1203,17 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ConnectInProgress) {
.Times(1) .Times(1)
.WillOnce(SaveArg<0>(&connect_callback)); .WillOnce(SaveArg<0>(&connect_callback));
ExtensionTestMessageListener listener("ready", true); ExtensionTestMessageListener listener(true);
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/connect_in_progress"))); "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()); connect_callback.Run(conn_ptr.Pass());
listener.Reset(); listener.Reset();
listener.WaitUntilSatisfied(); EXPECT_TRUE(listener.WaitUntilSatisfied());
ASSERT_EQ("ready", listener.message()) << listener.message();
disconnect_callback.Run(); disconnect_callback.Run();
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
...@@ -1250,6 +1271,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, StartStopNotifications) { ...@@ -1250,6 +1271,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, StartStopNotifications) {
session1)); session1));
ExtensionTestMessageListener listener("ready", true); ExtensionTestMessageListener listener("ready", true);
listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/start_stop_notifications"))); "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