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.
7 function testGetCharacteristic() {
8 if (error !== undefined) {
9 chrome.test.sendMessage('fail');
10 chrome.test.fail(error);
12 chrome.test.assertTrue(characteristic != null,
13 'Characteristic is null.');
14 chrome.test.assertEq('char_id0', characteristic.instanceId);
15 chrome.test.assertEq('00001211-0000-1000-8000-00805f9b34fb',
17 chrome.test.assertEq(false, characteristic.isLocal);
18 chrome.test.assertEq(serviceId, characteristic.service.instanceId);
19 chrome.test.assertEq(4, characteristic.properties.length);
20 chrome.test.assertTrue(characteristic.properties.indexOf('broadcast') > -1,
21 '\'broadcast\' not in characteristic.properties');
22 chrome.test.assertTrue(characteristic.properties.indexOf('read') > -1,
23 '\'read\' not in characteristic.properties');
24 chrome.test.assertTrue(characteristic.properties.indexOf('indicate') > -1,
25 '\'indicate\' not in characteristic.properties');
26 chrome.test.assertTrue(
27 characteristic.properties.indexOf('writeWithoutResponse') > -1,
28 '\'writeWithoutResponse\' not in characteristic.properties');
30 var valueBytes = new Uint8Array(characteristic.value);
31 chrome.test.assertEq(5, characteristic.value.byteLength);
32 chrome.test.assertEq(0x01, valueBytes[0]);
33 chrome.test.assertEq(0x02, valueBytes[1]);
34 chrome.test.assertEq(0x03, valueBytes[2]);
35 chrome.test.assertEq(0x04, valueBytes[3]);
36 chrome.test.assertEq(0x05, valueBytes[4]);
38 chrome.test.succeed();
41 var serviceId = 'service_id0';
42 var charId = 'char_id0';
43 var badCharId = 'char_id1';
45 var characteristic = null;
47 function expectFailed(result) {
48 if (result || !chrome.runtime.lastError) {
49 error = 'getCharacteristic call should have failed';
50 chrome.test.runTests([testGetCharacteristic]);
56 // 1. Unknown characteristic instanceId.
57 chrome.bluetoothLowEnergy.getCharacteristic(badCharId, function (result) {
58 if (!expectFailed(result))
61 // 2. Known characteristic instanceId, but the mapped device is unknown.
62 chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) {
63 if (!expectFailed(result))
66 // 3. Known characteristic instanceId, but the mapped service is unknown.
67 chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) {
68 if (!expectFailed(result))
71 // 4. Known characteristic instanceId, but the mapped service does not
72 // know about the characteristic.
73 chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) {
74 if (!expectFailed(result))
78 chrome.bluetoothLowEnergy.getCharacteristic(charId, function (result) {
79 if (chrome.runtime.lastError) {
80 error = 'Unexpected error: ' + chrome.runtime.lastError.message;
81 chrome.test.runTests([testGetCharacteristic]);
84 characteristic = result;
86 chrome.test.sendMessage('ready', function (message) {
87 chrome.test.runTests([testGetCharacteristic]);