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 testGetCharacteristics() {
8 if (error !== undefined) {
9 chrome.test.sendMessage('fail');
10 chrome.test.fail(error);
12 chrome.test.assertEq(2, chrcs.length);
14 chrome.test.assertEq('char_id0', chrcs[0].instanceId);
15 chrome.test.assertEq('00001211-0000-1000-8000-00805f9b34fb', chrcs[0].uuid);
16 chrome.test.assertEq(false, chrcs[0].isLocal);
17 chrome.test.assertEq(serviceId, chrcs[0].service.instanceId);
18 chrome.test.assertEq(4, chrcs[0].properties.length);
19 chrome.test.assertTrue(chrcs[0].properties.indexOf('broadcast') > -1,
20 '\'broadcast\' not in chrcs[0].properties');
21 chrome.test.assertTrue(chrcs[0].properties.indexOf('read') > -1,
22 '\'read\' not in chrcs[0].properties');
23 chrome.test.assertTrue(chrcs[0].properties.indexOf('indicate') > -1,
24 '\'indicate\' not in chrcs[0].properties');
25 chrome.test.assertTrue(
26 chrcs[0].properties.indexOf('writeWithoutResponse') > -1,
27 '\'writeWithoutResponse\' not in chrcs[0].properties');
29 var valueBytes = new Uint8Array(chrcs[0].value);
30 chrome.test.assertEq(5, chrcs[0].value.byteLength);
31 chrome.test.assertEq(0x01, valueBytes[0]);
32 chrome.test.assertEq(0x02, valueBytes[1]);
33 chrome.test.assertEq(0x03, valueBytes[2]);
34 chrome.test.assertEq(0x04, valueBytes[3]);
35 chrome.test.assertEq(0x05, valueBytes[4]);
37 chrome.test.assertEq('char_id1', chrcs[1].instanceId),
38 chrome.test.assertEq('00001212-0000-1000-8000-00805f9b34fb', chrcs[1].uuid);
39 chrome.test.assertEq(false, chrcs[1].isLocal);
40 chrome.test.assertEq(serviceId, chrcs[1].service.instanceId);
41 chrome.test.assertEq(3, chrcs[1].properties.length);
42 chrome.test.assertTrue(chrcs[1].properties.indexOf('read') > -1,
43 '\'read\' not in chrcs[1].properties');
44 chrome.test.assertTrue(chrcs[1].properties.indexOf('write') > -1,
45 '\'write\' not in chrcs[1].properties');
46 chrome.test.assertTrue(chrcs[1].properties.indexOf('notify') > -1,
47 '\'notify\' not in chrcs[1].properties');
49 valueBytes = new Uint8Array(chrcs[1].value);
50 chrome.test.assertEq(3, chrcs[1].value.byteLength);
51 chrome.test.assertEq(0x06, valueBytes[0]);
52 chrome.test.assertEq(0x07, valueBytes[1]);
53 chrome.test.assertEq(0x08, valueBytes[2]);
55 chrome.test.succeed();
58 var serviceId = 'service_id0';
61 function earlyError(message) {
63 chrome.test.runTests([testGetCharacteristics]);
66 function expectSuccess() {
67 if (chrome.runtime.lastError) {
68 earlyError('Unexpected Error: ' + chrome.runtime.lastError.message);
70 return error !== undefined;
73 chrome.bluetoothLowEnergy.getCharacteristics(serviceId, function (result) {
74 if (result || !chrome.runtime.lastError) {
75 earlyError('getCharacteristics should have failed.');
79 chrome.bluetoothLowEnergy.getCharacteristics(serviceId, function (result) {
83 if (!result || result.length != 0) {
84 earlyError('Characteristics should be empty.');
88 chrome.bluetoothLowEnergy.getCharacteristics(serviceId, function (result) {
94 chrome.test.sendMessage('ready', function (message) {
95 chrome.test.runTests([testGetCharacteristics]);