OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../resources/testharness.js"></script> | 2 <script src="../resources/testharness.js"></script> |
3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
4 <script src="resources/bluetooth-helpers.js"></script> | 4 <script src="resources/bluetooth-helpers.js"></script> |
5 <script> | 5 <script> |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 test(t => { assert_true(window.testRunner instanceof Object); t.done(); }, | 8 test(t => { assert_true(window.testRunner instanceof Object); t.done(); }, |
9 'window.testRunner is required for the following tests.'); | 9 'window.testRunner is required for the following tests.'); |
10 | 10 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 return requestDeviceWithKeyDown({filters: [{services: [testSpec.uuid]}]}) | 110 return requestDeviceWithKeyDown({filters: [{services: [testSpec.uuid]}]}) |
111 .then(device => { | 111 .then(device => { |
112 assert_promise_rejects_with_message( | 112 assert_promise_rejects_with_message( |
113 device.connectGATT(), | 113 device.connectGATT(), |
114 testSpec.error, | 114 testSpec.error, |
115 'Adapter failed to connect to device.'); | 115 'Adapter failed to connect to device.'); |
116 }); | 116 }); |
117 }, testSpec.testName); | 117 }, testSpec.testName); |
118 }); | 118 }); |
119 | 119 |
| 120 // TODO(ortuno): Allow connections when the tab is in the background. |
| 121 // This is a short term solution instead of implementing a tab indicator |
| 122 // for bluetooth connections. |
| 123 // https://crbug.com/579746 |
| 124 promise_test(() => { |
| 125 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); |
| 126 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) |
| 127 .then(device => { |
| 128 testRunner.setPageVisibility('hidden'); |
| 129 return assert_promise_rejects_with_message( |
| 130 device.connectGATT(), |
| 131 new DOMException('Connection is only allowed while the page is visible.
' + |
| 132 'This is a temporary measure until we are able to ' + |
| 133 'effectively communicate to the user that a page is ' + |
| 134 'connected to a device.', |
| 135 'SecurityError')); |
| 136 }) |
| 137 .then(() => testRunner.setPageVisibility('visible')) |
| 138 .catch(error => { |
| 139 testRunner.setPageVisibility('visible'); |
| 140 throw error; |
| 141 }); |
| 142 }, 'Device should not be able to connect in background.'); |
| 143 |
120 promise_test(() => { | 144 promise_test(() => { |
121 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 145 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); |
122 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) | 146 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) |
123 .then(device => device.connectGATT()) | 147 .then(device => device.connectGATT()) |
124 .then(gattServer => assert_true(gattServer.connected)); | 148 .then(gattServer => assert_true(gattServer.connected)); |
125 }, 'Device will connect'); | 149 }, 'Device will connect'); |
126 | 150 |
127 promise_test(() => { | 151 promise_test(() => { |
128 testRunner.setBluetoothMockDataSet(''); | 152 testRunner.setBluetoothMockDataSet(''); |
129 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 153 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); |
130 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) | 154 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) |
131 .then(device => { | 155 .then(device => { |
132 return Promise.all([device.connectGATT(), device.connectGATT()]) | 156 return Promise.all([device.connectGATT(), device.connectGATT()]) |
133 }).then(gattServers => { | 157 }).then(gattServers => { |
134 // connectGATT should return the same object if it was created earlier. | 158 // connectGATT should return the same object if it was created earlier. |
135 // TODO(ortuno): change to assert_equals. | 159 // TODO(ortuno): change to assert_equals. |
136 assert_not_equals(gattServers[0], gattServers[1]); | 160 assert_not_equals(gattServers[0], gattServers[1]); |
137 }); | 161 }); |
138 }); | 162 }); |
139 </script> | 163 </script> |
OLD | NEW |