Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / bluetooth / getPrimaryService.html
blob870ea7c8e2bb81c18c594fd7622716fd31dc907d
1 <!DOCTYPE html>
2 <script src="../resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script>
4 <script src="resources/bluetooth-helpers.js"></script>
5 <script>
6 'use strict'
8 test(t => { assert_true(window.testRunner instanceof Object); t.done(); },
9 'window.testRunner is required for the following tests.');
11 promise_test(() => {
12 testRunner.setBluetoothMockDataSet('GenericAccessAdapter');
13 return requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]})
14 .then(device => device.connectGATT())
15 .then(gattServer => {
16 testRunner.setBluetoothMockDataSet('EmptyAdapter');
17 return assert_promise_rejects_with_message(
18 gattServer.getPrimaryService('generic_access'), {
19 name: 'NetworkError',
20 message: 'Bluetooth Device is no longer in range.'
21 }, 'Device went out of range.');
22 });
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)]))
33 .then(services => {
34 services.forEach(service => {
35 assert_equals(service, null,
36 'Non existent services should return null.');
37 });
38 });
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)]))
49 .then(services => {
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.');
55 });
56 });
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)]))
70 .then(services => {
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.');
78 });
79 }, 'Calls to get the same service should return the same object.');
81 promise_test(() => {
82 testRunner.setBluetoothMockDataSet('GenericAccessAdapter');
83 return requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]})
84 .then(device => device.connectGATT())
85 .then(gattServer => {
86 return assert_promise_rejects_with_message(
87 gattServer.getPrimaryService('wrong_name'), {
88 name: 'SyntaxError',
89 message: 'Failed to execute \'getPrimaryService\' on ' +
90 '\'BluetoothGATTRemoteServer\': Invalid Service name: ' +
91 '\'wrong_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.');
99 });
100 }, 'Wrong Service name. Reject with SyntaxError.');
101 </script>