| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var deviceAddress0 = '11:22:33:44:55:66'; | 5 var deviceAddress0 = '11:22:33:44:55:66'; |
| 6 var ble = chrome.bluetoothLowEnergy; | 6 var ble = chrome.bluetoothLowEnergy; |
| 7 | 7 |
| 8 var errorInProgress = 'In progress'; | 8 var errorInProgress = 'In progress'; |
| 9 var errorNotConnected = 'Not connected'; |
| 9 | 10 |
| 10 function expectError(message) { | 11 function expectError(message) { |
| 11 if (!chrome.runtime.lastError || | 12 if (!chrome.runtime.lastError || |
| 12 chrome.runtime.lastError.message != message) | 13 chrome.runtime.lastError.message != message) |
| 13 chrome.test.sendMessage('Expected error: <' + message + '> got <' | 14 chrome.test.sendMessage('Expected error: <' + message + '> got <' |
| 14 + chrome.runtime.lastError.message + '>'); | 15 + chrome.runtime.lastError.message + '>'); |
| 15 } | 16 } |
| 16 | 17 |
| 17 function expectSuccess() { | 18 function expectSuccess() { |
| 18 if (chrome.runtime.lastError) | 19 if (chrome.runtime.lastError) |
| 19 chrome.test.sendMessage('Unexpected error: ' | 20 chrome.test.sendMessage('Unexpected error: ' |
| 20 + chrome.runtime.lastError.message); | 21 + chrome.runtime.lastError.message); |
| 21 } | 22 } |
| 22 | 23 |
| 23 ble.connect(deviceAddress0, function () { | 24 ble.connect(deviceAddress0, function () { |
| 24 expectSuccess(); | 25 expectSuccess(); |
| 25 ble.disconnect(deviceAddress0, function () { | 26 ble.disconnect(deviceAddress0, function () { |
| 26 chrome.test.succeed(); | 27 chrome.test.succeed(); |
| 27 }); | 28 }); |
| 28 | 29 |
| 29 ble.disconnect(deviceAddress0, function () { | 30 ble.disconnect(deviceAddress0, function () { |
| 30 expectError(errorInProgress); | 31 expectError(errorNotConnected); |
| 31 chrome.test.sendMessage('ready'); | 32 chrome.test.sendMessage( |
| 33 'After 2nd call to disconnect.'); |
| 32 }); | 34 }); |
| 33 }); | 35 }); |
| 34 | 36 |
| 35 ble.connect(deviceAddress0, function () { | 37 ble.connect(deviceAddress0, function () { |
| 36 expectError(errorInProgress); | 38 expectError(errorInProgress); |
| 37 chrome.test.sendMessage('ready'); | 39 chrome.test.sendMessage( |
| 40 'After 2nd connect fails due to 1st connect being in progress.'); |
| 38 }); | 41 }); |
| OLD | NEW |