| Index: chrome/test/data/extensions/api_test/bluetooth_low_energy/gatt_connection/runtest.js
|
| diff --git a/chrome/test/data/extensions/api_test/bluetooth_low_energy/gatt_connection/runtest.js b/chrome/test/data/extensions/api_test/bluetooth_low_energy/gatt_connection/runtest.js
|
| index 0c8122e4699af4c219e5bee33240dc99d563837b..73615a6e438dd6d14fb7055abf6ad1eab0d3e321 100644
|
| --- a/chrome/test/data/extensions/api_test/bluetooth_low_energy/gatt_connection/runtest.js
|
| +++ b/chrome/test/data/extensions/api_test/bluetooth_low_energy/gatt_connection/runtest.js
|
| @@ -11,11 +11,19 @@ var errorAlreadyConnected = 'Already connected';
|
| var errorNotConnected = 'Not connected';
|
| var errorNotFound = 'Instance not found';
|
| var errorOperationFailed = 'Operation failed';
|
| +var errorAuthFailed = 'Authentication failed';
|
| +var errorInProgress = 'In progress';
|
| +var errorCanceled = 'Request canceled';
|
| +var errorTimeout = 'Operation timed out';
|
| +var errorUnsupportedDevice = 'This device is not supported on ' +
|
| + 'the current platform';
|
|
|
| function expectError(message) {
|
| - if (!chrome.runtime.lastError ||
|
| - chrome.runtime.lastError.message != message)
|
| - chrome.test.fail('Expected error: ' + message);
|
| + if (!chrome.runtime.lastError)
|
| + chrome.test.fail('Expected error: <' + message + '> but there was none.');
|
| + if (chrome.runtime.lastError.message != message)
|
| + chrome.test.fail('Expected error: <' + message + '> but it was: <' +
|
| + chrome.runtime.lastError.message + '>');
|
| }
|
|
|
| function expectSuccess() {
|
| @@ -23,79 +31,97 @@ function expectSuccess() {
|
| chrome.test.fail('Unexpected error: ' + chrome.runtime.lastError.message);
|
| }
|
|
|
| -// Disconnecting from unconnected devices should fail.
|
| -ble.disconnect(deviceAddress0, function () {
|
| +var queue = [];
|
| +
|
| +function runNext() {
|
| + if (queue.length == 0) {
|
| + chrome.test.fail("No more tests!");
|
| + }
|
| + (queue.shift())();
|
| +}
|
| +
|
| +function makeConnectErrorFunction(error) {
|
| + return function() {
|
| + expectError(error);
|
| +
|
| + ble.connect(deviceAddress0, runNext);
|
| + };
|
| +}
|
| +
|
| +queue = [function() {
|
| + ble.disconnect(deviceAddress0, runNext);
|
| +}, function() {
|
| expectError(errorNotConnected);
|
| - ble.disconnect(deviceAddress1, function () {
|
| - expectError(errorNotConnected);
|
| - ble.disconnect(badDeviceAddress, function () {
|
| - expectError(errorNotConnected);
|
| -
|
| - // Connect to device that doesn't exist.
|
| - ble.connect(badDeviceAddress, function () {
|
| - expectError(errorNotFound);
|
| -
|
| - // Failed connect to device 1.
|
| - ble.connect(deviceAddress0, function () {
|
| - expectError(errorOperationFailed);
|
| -
|
| - // Successful connect to device 0.
|
| - ble.connect(deviceAddress0, function () {
|
| - expectSuccess();
|
| -
|
| - // Device 0 already connected.
|
| - ble.connect(deviceAddress0, function() {
|
| - expectError(errorAlreadyConnected);
|
| -
|
| - // Device 1 still disconnected.
|
| - ble.disconnect(deviceAddress1, function () {
|
| - expectError(errorNotConnected);
|
| -
|
| - // Successful connect to device 1.
|
| - ble.connect(deviceAddress1, function () {
|
| - expectSuccess();
|
| -
|
| - // Device 1 already connected.
|
| - ble.connect(deviceAddress1, function () {
|
| - expectError(errorAlreadyConnected);
|
| -
|
| - // Successfully disconnect device 0.
|
| - ble.disconnect(deviceAddress0, function () {
|
| - expectSuccess();
|
| -
|
| - // Cannot disconnect device 0.
|
| - ble.disconnect(deviceAddress0, function () {
|
| - expectError(errorNotConnected);
|
| -
|
| - // Device 1 still connected.
|
| - ble.connect(deviceAddress1, function () {
|
| - expectError(errorAlreadyConnected);
|
| -
|
| - // Successfully disconnect device 1.
|
| - ble.disconnect(deviceAddress1, function () {
|
| - expectSuccess();
|
| -
|
| - // Cannot disconnect device 1.
|
| - ble.disconnect(deviceAddress1, function () {
|
| - expectError(errorNotConnected);
|
| -
|
| - // Re-connect device 0.
|
| - ble.connect(deviceAddress0, function () {
|
| - expectSuccess();
|
| - chrome.test.succeed();
|
| - });
|
| - });
|
| - });
|
| - });
|
| - });
|
| - });
|
| - });
|
| - });
|
| - });
|
| - });
|
| - });
|
| - })
|
| - });
|
| - });
|
| - });
|
| -});
|
| +
|
| + // Disconnect from deviceAddress1, (not connected)
|
| + ble.disconnect(deviceAddress1, runNext);
|
| +}, function () {
|
| + expectError(errorNotConnected);
|
| +
|
| + // Connect to device that doesn't exist.
|
| + ble.connect(badDeviceAddress, runNext);
|
| +},
|
| + makeConnectErrorFunction(errorNotFound),
|
| + makeConnectErrorFunction(errorOperationFailed),
|
| + makeConnectErrorFunction(errorInProgress),
|
| + makeConnectErrorFunction(errorAuthFailed),
|
| + makeConnectErrorFunction(errorAuthFailed),
|
| + makeConnectErrorFunction(errorCanceled),
|
| + makeConnectErrorFunction(errorTimeout),
|
| + makeConnectErrorFunction(errorUnsupportedDevice),
|
| +function () {
|
| + expectSuccess();
|
| +
|
| + // Device 0 already connected.
|
| + ble.connect(deviceAddress0, runNext);
|
| +}, function () {
|
| + expectError(errorAlreadyConnected);
|
| +
|
| + // Device 1 still disconnected.
|
| + ble.disconnect(deviceAddress1, runNext);
|
| +}, function () {
|
| + expectError(errorNotConnected);
|
| +
|
| + // Successful connect to device 1.
|
| + ble.connect(deviceAddress1, runNext);
|
| +}, function () {
|
| + expectSuccess();
|
| +
|
| + // Device 1 already connected.
|
| + ble.connect(deviceAddress1, runNext);
|
| +}, function () {
|
| + expectError(errorAlreadyConnected);
|
| +
|
| + // Successfully disconnect device 0.
|
| + ble.disconnect(deviceAddress0, runNext);
|
| +}, function () {
|
| + expectSuccess();
|
| +
|
| + // Cannot disconnect device 0.
|
| + ble.disconnect(deviceAddress0, runNext);
|
| +}, function () {
|
| + expectError(errorNotConnected);
|
| +
|
| + // Device 1 still connected.
|
| + ble.connect(deviceAddress1, runNext);
|
| +}, function () {
|
| + expectError(errorAlreadyConnected);
|
| +
|
| + // Successfully disconnect device 1.
|
| + ble.disconnect(deviceAddress1, runNext);
|
| +}, function () {
|
| + expectSuccess();
|
| +
|
| + // Cannot disconnect device 1.
|
| + ble.disconnect(deviceAddress1, runNext);
|
| +}, function () {
|
| + expectError(errorNotConnected);
|
| +
|
| + // Re-connect device 0.
|
| + ble.connect(deviceAddress0, runNext);
|
| +}, function () {
|
| + expectSuccess();
|
| + chrome.test.succeed();
|
| +}];
|
| +
|
| +runNext();
|
|
|