OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 function failOnError(result) { |
| 6 if (chrome.runtime.lastError || !result) { |
| 7 chrome.test.fail(chrome.runtime.lastError.message); |
| 8 return true; |
| 9 } |
| 10 return false; |
| 11 } |
| 12 |
| 13 function failOnSuccess() { |
| 14 if (!chrome.runtime.lastError) { |
| 15 chrome.test.fail('lastError not set, operation succeeded.'); |
| 16 return true; |
| 17 } |
| 18 return false; |
| 19 } |
| 20 |
| 21 var service = { uuid: '00001234-0000-1000-8000-00805f9b34fb', isPrimary: true }; |
| 22 chrome.bluetoothLowEnergy.createService(service, function(serviceId) { |
| 23 if (failOnError(serviceId)) |
| 24 return; |
| 25 |
| 26 var characteristic = { uuid: '00001234-0000-1000-8000-00805f9b34fa', |
| 27 properties: ['read']}; |
| 28 chrome.bluetoothLowEnergy.createCharacteristic(characteristic, serviceId, |
| 29 function(characteristicId) { |
| 30 if (failOnError(characteristicId)) |
| 31 return; |
| 32 |
| 33 var descriptor = { uuid: '00001234-0000-1000-8000-00805f9b34fc' }; |
| 34 // Invalid characteristic ID. |
| 35 chrome.bluetoothLowEnergy.createDescriptor(descriptor, |
| 36 'invalidCharacteristicId', function(descriptorId) { |
| 37 if (failOnSuccess()) |
| 38 return; |
| 39 |
| 40 // Valid characteristic ID. |
| 41 chrome.bluetoothLowEnergy.createDescriptor(descriptor, characteristicId, |
| 42 function(descriptorId) { |
| 43 if (failOnError(descriptorId)) |
| 44 return; |
| 45 |
| 46 chrome.test.succeed(); |
| 47 }); |
| 48 }); |
| 49 }); |
| 50 }); |
OLD | NEW |