| Index: chrome/test/data/extensions/api_test/bluetooth_low_energy/get_service/runtest.js
|
| diff --git a/chrome/test/data/extensions/api_test/bluetooth_low_energy/get_service/runtest.js b/chrome/test/data/extensions/api_test/bluetooth_low_energy/get_service/runtest.js
|
| index ac1a9f50ace322e17966fb1ec48620218ac236ea..e2a2d683f6680c983eefb782c1a81f0ca4950020 100644
|
| --- a/chrome/test/data/extensions/api_test/bluetooth_low_energy/get_service/runtest.js
|
| +++ b/chrome/test/data/extensions/api_test/bluetooth_low_energy/get_service/runtest.js
|
| @@ -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) {
|
|
|