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 testGetDescriptor() {
8 if (error !== undefined) {
9 chrome.test.sendMessage('fail');
10 chrome.test.fail(error);
12 chrome.test.assertTrue(descriptor != null, '\'descriptor\' is null');
14 chrome.test.assertEq('desc_id0', descriptor.instanceId);
15 chrome.test.assertEq('00001221-0000-1000-8000-00805f9b34fb', descriptor.uuid);
16 chrome.test.assertEq(false, descriptor.isLocal);
17 chrome.test.assertEq(charId, descriptor.characteristic.instanceId);
19 var valueBytes = new Uint8Array(descriptor.value);
20 chrome.test.assertEq(3, descriptor.value.byteLength);
21 chrome.test.assertEq(0x01, valueBytes[0]);
22 chrome.test.assertEq(0x02, valueBytes[1]);
23 chrome.test.assertEq(0x03, valueBytes[2]);
25 chrome.test.succeed();
28 var getDescriptor = chrome.bluetoothLowEnergy.getDescriptor;
30 var charId = 'char_id0';
31 var descId = 'desc_id0';
32 var badDescId = 'desc_id1';
34 var descriptor = null;
36 function earlyError(message) {
38 chrome.test.runTests([testGetDescriptor]);
41 function expectError(result) {
42 if (result || !chrome.runtime.lastError) {
43 earlyError('getDescriptor should have failed');
45 return error !== undefined;
48 // 1. Unknown descriptor instanceId.
49 getDescriptor(badDescId, function (result) {
50 if (result || !chrome.runtime.lastError) {
51 earlyError('getDescriptor should have failed for \'badDescId\'');
55 // 2. Known descriptor instanceId, but the mapped device is unknown.
56 getDescriptor(descId, function (result) {
57 if (expectError(result))
60 // 3. Known descriptor instanceId, but the mapped service is unknown.
61 getDescriptor(descId, function (result) {
62 if (expectError(result))
65 // 4. Known descriptor instanceId, but the mapped characteristic is
67 getDescriptor(descId, function (result) {
68 if (expectError(result))
71 // 5. Known descriptor instanceId, but the mapped the characteristic
72 // does not know about the descriptor.
73 getDescriptor(descId, function (result) {
74 if (expectError(result))
78 getDescriptor(descId, function (result) {
79 if (chrome.runtime.lastError) {
80 earlyError(chrome.runtime.lastError.message);
86 chrome.test.sendMessage('ready', function (message) {
87 chrome.test.runTests([testGetDescriptor]);