Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / bluetooth / connectGATT.html
blob03c4442dfaa6be24bf012454ef889ba28f15bc58
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 => {
15 testRunner.setBluetoothMockDataSet('EmptyAdapter');
16 return assert_promise_rejects_with_message(
17 device.connectGATT(),{
18 name: 'NetworkError',
19 message: 'Bluetooth Device is no longer in range.'
20 }, 'Device went out of range.');
21 });
22 }, 'Device goes out of range. Reject with NetworkError.');
24 // The following tests make sure the Web Bluetooth implementation
25 // responds correctly to the different types of errors the
26 // underlying platform might throw.
28 // Each implementation maps these devices to specific code paths
29 // that result in different errors thus increasing code coverage
30 // when testing. Therefore some of these devices might not be useful
31 // for all implementations.
33 testName: 'Unknown error when connnecting.',
34 uuid: errorUUID(0x0),
35 error: {
36 name: 'NetworkError',
37 message: 'Unknown error when connecting to the device.'
39 }, {
40 testName: 'Connection was already in progress.',
41 uuid: errorUUID(0x1),
42 error: {
43 name: 'NetworkError',
44 message: 'Connection already in progress.'
46 }, {
47 testName: 'Connection failed.',
48 uuid: errorUUID(0x2),
49 error: {
50 name: 'NetworkError',
51 message: 'Connection failed for unknown reason.'
53 }, {
54 testName: 'Authentication failed when connecting.',
55 uuid: errorUUID(0x3),
56 error: {
57 name: 'NetworkError',
58 message: 'Authentication failed.'
60 }, {
61 testName: 'Authentication canceled when connecting.',
62 uuid: errorUUID(0x4),
63 error: {
64 name: 'NetworkError',
65 message: 'Authentication canceled.'
67 }, {
68 testName: 'Authentication rejected when connecting.',
69 uuid: errorUUID(0x5),
70 error: {
71 name: 'NetworkError',
72 message: 'Authentication rejected.'
74 }, {
75 testName: 'Authentication timed out when connecting.',
76 uuid: errorUUID(0x6),
77 error: {
78 name: 'NetworkError',
79 message: 'Authentication timeout.'
81 }, {
82 testName: 'Tried to connect to an unsupported device.',
83 uuid: errorUUID(0x7),
84 error: {
85 name: 'NetworkError',
86 message: 'Unsupported device.'
88 }].forEach(testSpec => {
89 promise_test(() => {
90 testRunner.setBluetoothMockDataSet('FailingConnectionsAdapter');
91 return requestDeviceWithKeyDown({filters: [{services: [testSpec.uuid]}]})
92 .then(device => {
93 assert_promise_rejects_with_message(
94 device.connectGATT(),
95 testSpec.error,
96 'Adapter failed to connect to device.');
97 });
98 }, testSpec.testName);
99 });
101 promise_test(() => {
102 testRunner.setBluetoothMockDataSet('GenericAccessAdapter');
103 return requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]})
104 .then(device => device.connectGATT())
105 .then(gattServer => assert_true(gattServer.connected));
106 }, 'Device will connect');
107 </script>