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())
16 testRunner
.setBluetoothMockDataSet('EmptyAdapter');
17 return assert_promise_rejects_with_message(
18 gattServer
.getPrimaryService('generic_access'), {
20 message
: 'Bluetooth Device is no longer in range.'
21 }, 'Device went out of range.');
23 }, 'Device goes out of range. Reject with NetworkError.');
25 promise_test(function() {
26 testRunner
.setBluetoothMockDataSet('GenericAccessAdapter');
27 return requestDeviceWithKeyDown({filters
: [{services
: ['generic_access']}]})
28 .then(device
=> device
.connectGATT())
29 .then(gattServer
=> Promise
.all(
30 [gattServer
.getPrimaryService(heart_rate
.alias
),
31 gattServer
.getPrimaryService(heart_rate
.name
),
32 gattServer
.getPrimaryService(heart_rate
.uuid
)]))
34 services
.forEach(service
=> {
35 assert_equals(service
, null,
36 'Non existent services should return null.');
39 }, 'Request for wrong service. Should return null.');
41 promise_test(function() {
42 testRunner
.setBluetoothMockDataSet('GenericAccessAdapter');
43 return requestDeviceWithKeyDown({filters
: [{services
: ['generic_access']}]})
44 .then(device
=> device
.connectGATT())
45 .then(gattServer
=> Promise
.all(
46 [gattServer
.getPrimaryService(generic_access
.alias
),
47 gattServer
.getPrimaryService(generic_access
.name
),
48 gattServer
.getPrimaryService(generic_access
.uuid
)]))
50 services
.forEach(service
=> {
51 assert_equals(service
.uuid
, generic_access
.uuid
,
52 'Service UUID should be the same as requested UUID.');
53 assert_true(service
.isPrimary
,
54 'getPrimaryService should return a primary service.');
57 }, 'Request for service. Should return right service');
59 promise_test(function() {
60 testRunner
.setBluetoothMockDataSet('GenericAccessAdapter');
61 return requestDeviceWithKeyDown({filters
: [{services
: ['generic_access']}]})
62 .then(device
=> device
.connectGATT())
63 .then(gattServer
=> Promise
.all(
64 [gattServer
.getPrimaryService(generic_access
.alias
),
65 gattServer
.getPrimaryService(generic_access
.alias
),
66 gattServer
.getPrimaryService(generic_access
.name
),
67 gattServer
.getPrimaryService(generic_access
.name
),
68 gattServer
.getPrimaryService(generic_access
.uuid
),
69 gattServer
.getPrimaryService(generic_access
.uuid
)]))
71 // getPrimaryService should return the same object if it was created
72 // earlier. https://crbug.com/495270
73 // TODO(ortuno): Change to assert_equals.
74 for (let i
= 1; i
< services
.length
; i
++) {
75 assert_not_equals(services
[0], services
[i
],
76 'Should return the same service as the first call.');
79 }, 'Calls to get the same service should return the same object.');
82 testRunner
.setBluetoothMockDataSet('GenericAccessAdapter');
83 return requestDeviceWithKeyDown({filters
: [{services
: ['generic_access']}]})
84 .then(device
=> device
.connectGATT())
86 return assert_promise_rejects_with_message(
87 gattServer
.getPrimaryService('wrong_name'), {
89 message
: 'Failed to execute \'getPrimaryService\' on ' +
90 '\'BluetoothGATTRemoteServer\': Invalid Service name: ' +
92 'It must be a valid UUID alias (e.g. 0x1234), ' +
93 'UUID (lowercase hex characters e.g. ' +
94 '\'00001234-0000-1000-8000-00805f9b34fb\'), ' +
95 'or recognized standard name from ' +
96 'https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx' +
97 ' e.g. \'alert_notification\'.'
98 }, 'Wrong Service name passed.');
100 }, 'Wrong Service name. Reject with SyntaxError.');