2 <script src=
"../resources/testharness.js"></script>
3 <script src=
"../resources/testharnessreport.js"></script>
4 <script src=
"resources/bluetooth-helpers.js"></script>
8 test(t
=> { assert_true(window
.testRunner
instanceof Object
); t
.done(); },
9 'window.testRunner is required for the following tests.');
12 testRunner
.setBluetoothMockDataSet('GenericAccessAdapter');
13 return requestDeviceWithKeyDown({filters
: [{services
: ['generic_access']}]})
14 .then(device
=> device
.connectGATT())
15 .then(gattServer
=> gattServer
.getPrimaryService('generic_access'))
17 testRunner
.setBluetoothMockDataSet('EmptyAdapter');
18 return assert_promise_rejects_with_message(
19 service
.getCharacteristic('gap.device_name'), {
21 message
: 'Bluetooth Device is no longer in range.'
22 }, 'Device went out of range.');
24 }, 'Device goes out of range. Reject with NetworkError.');
27 testRunner
.setBluetoothMockDataSet('GenericAccessAdapter');
28 return requestDeviceWithKeyDown({filters
: [{services
: ['generic_access']}]})
29 .then(device
=> device
.connectGATT())
30 .then(gattService
=> gattService
.getPrimaryService('generic_access'))
32 testRunner
.setBluetoothMockDataSet('MissingServiceGenericAccessAdapter');
33 return assert_promise_rejects_with_message(
34 service
.getCharacteristic('gap.device_name'), {
35 name
: 'InvalidStateError',
36 message
: 'GATT Service no longer exists.'
37 }, 'Service got removed.');
39 }, 'Service is removed. Reject with InvalidStateError.');
43 testRunner
.setBluetoothMockDataSet('GenericAccessAdapter');
44 return requestDeviceWithKeyDown({filters
: [{services
: ['generic_access']}]})
45 .then(device
=> device
.connectGATT())
46 .then(gattServer
=> gattServer
.getPrimaryService('generic_access'))
47 .then(service
=> Promise
.all(
48 [service
.getCharacteristic(battery_level
.alias
),
49 service
.getCharacteristic(battery_level
.name
),
50 service
.getCharacteristic(battery_level
.uuid
)]))
51 .then(characteristics
=> {
52 characteristics
.forEach(characteristic
=> {
53 assert_equals(characteristic
, null,
54 'Non existent characteristic should return null.');
57 }, 'Request for wrong characteristic. Should return null.');
60 testRunner
.setBluetoothMockDataSet('GenericAccessAdapter');
61 return requestDeviceWithKeyDown({filters
: [{services
: ['generic_access']}]})
62 .then(device
=> device
.connectGATT())
63 .then(gattServer
=> gattServer
.getPrimaryService('generic_access'))
64 .then(service
=> Promise
.all(
65 [service
.getCharacteristic(device_name
.alias
),
66 service
.getCharacteristic(device_name
.name
),
67 service
.getCharacteristic(device_name
.uuid
)]))
68 .then(characteristics
=> {
69 characteristics
.forEach(characteristic
=> {
71 characteristic
.uuid
, device_name
.uuid
,
72 'Characteristic UUID should be the same as requested UUID.');
75 }, 'Request for characteristic. Should return right characteristic');
78 testRunner
.setBluetoothMockDataSet('GenericAccessAdapter');
79 return requestDeviceWithKeyDown({filters
: [{services
: ['generic_access']}]})
80 .then(device
=> device
.connectGATT())
81 .then(gattServer
=> gattServer
.getPrimaryService('generic_access'))
82 .then(services
=> Promise
.all(
83 [services
.getCharacteristic(device_name
.alias
),
84 services
.getCharacteristic(device_name
.alias
),
85 services
.getCharacteristic(device_name
.name
),
86 services
.getCharacteristic(device_name
.name
),
87 services
.getCharacteristic(device_name
.uuid
),
88 services
.getCharacteristic(device_name
.uuid
)]))
89 .then(characteristics
=> {
90 // TODO(ortuno): getCharacteristic should return the same object
91 // if it was created earlier.
92 // https://crbug.com/495270
93 for (var i
= 1; i
< characteristics
.length
; i
++) {
95 characteristics
[0], characteristics
[i
],
96 'Should return the same characteristic as the first call.');
99 }, 'Calls to get the same characteristic should return the same object.');
102 testRunner
.setBluetoothMockDataSet('GenericAccessAdapter');
103 return requestDeviceWithKeyDown({filters
: [{services
: ['generic_access']}]})
104 .then(device
=> device
.connectGATT())
105 .then(gattServer
=> gattServer
.getPrimaryService('generic_access'))
107 return assert_promise_rejects_with_message(
108 service
.getCharacteristic('wrong_name'), {
110 message
: 'Failed to execute \'getCharacteristic\' on ' +
111 '\'BluetoothGATTService\': \Invalid Characteristic name: ' +
113 'It must be a valid UUID alias (e.g. 0x1234), ' +
114 'UUID (lowercase hex characters e.g. ' +
115 '\'00001234-0000-1000-8000-00805f9b34fb\'), ' +
116 'or recognized standard name from ' +
117 'https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicsHome.aspx' +
118 ' e.g. \'aerobic_heart_rate_lower_limit\'.'
119 }, 'Wrong Characteristic name passed.');
121 }, 'Wrong Characteristic name. Reject with SyntaxError.');