| 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 // Services Discovered |
| 9 // We use a connection to trigger a service discovered event and test |
| 10 // getPrimaryService. Sometimes the previous test left a connection to the |
| 11 // device open, so the event doesn't get triggered. To avoid this some tests |
| 12 // clean the state before starting the test. |
| 13 // In the future we will avoid this by |
| 14 // (1) Separating each test into it's own file. http://crbug.com/554240 |
| 15 // (2) Implementing Dynamic mocks so that we can trigger the |
| 16 // discovery event manually. http://crbug.com/569709 |
| 8 test(t => { assert_true(window.testRunner instanceof Object); t.done(); }, | 17 test(t => { assert_true(window.testRunner instanceof Object); t.done(); }, |
| 9 'window.testRunner is required for the following tests.'); | 18 'window.testRunner is required for the following tests.'); |
| 10 | 19 |
| 11 promise_test(() => { | 20 promise_test(() => { |
| 12 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 21 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); |
| 13 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) | 22 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) |
| 14 .then(device => device.connectGATT()) | 23 .then(device => device.connectGATT()) |
| 15 .then(gattServer => { | 24 .then(gattServer => { |
| 16 testRunner.setBluetoothMockDataSet('EmptyAdapter'); | 25 testRunner.setBluetoothMockDataSet('EmptyAdapter'); |
| 17 return assert_promise_rejects_with_message( | 26 return assert_promise_rejects_with_message( |
| 18 gattServer.getPrimaryService('generic_access'), | 27 gattServer.getPrimaryService('generic_access'), |
| 19 new DOMException('Bluetooth Device is no longer in range.', | 28 new DOMException('Bluetooth Device is no longer in range.', |
| 20 'NetworkError'), | 29 'NetworkError'), |
| 21 'Device went out of range.'); | 30 'Device went out of range.'); |
| 22 }); | 31 }); |
| 23 }, 'Device goes out of range. Reject with NetworkError.'); | 32 }, 'Device goes out of range. Reject with NetworkError.'); |
| 24 | 33 |
| 25 promise_test(() => { | 34 promise_test(() => { |
| 35 // See Services Discovered note above. |
| 36 testRunner.setBluetoothMockDataSet(''); |
| 26 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 37 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); |
| 27 let expected = new DOMException('Service not found in device.', | 38 let expected = new DOMException('Service not found in device.', |
| 28 'NotFoundError'); | 39 'NotFoundError'); |
| 29 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) | 40 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) |
| 30 .then(device => device.connectGATT()) | 41 .then(device => device.connectGATT()) |
| 31 .then(gattServer => Promise.all( | 42 .then(gattServer => Promise.all( |
| 32 [assert_promise_rejects_with_message( | 43 [assert_promise_rejects_with_message( |
| 33 gattServer.getPrimaryService(glucose.alias), expected), | 44 gattServer.getPrimaryService(glucose.alias), expected), |
| 34 assert_promise_rejects_with_message( | 45 assert_promise_rejects_with_message( |
| 35 gattServer.getPrimaryService(glucose.name), expected), | 46 gattServer.getPrimaryService(glucose.name), expected), |
| 36 assert_promise_rejects_with_message( | 47 assert_promise_rejects_with_message( |
| 37 gattServer.getPrimaryService(glucose.uuid), expected)])); | 48 gattServer.getPrimaryService(glucose.uuid), expected)])); |
| 38 }, 'Request for wrong service. Reject with NotFoundError.'); | 49 }, 'Request for wrong service. Reject with NotFoundError.'); |
| 39 | 50 |
| 40 promise_test(() => { | 51 promise_test(() => { |
| 41 // Because state doesn't get cleaned after each test in a file, we need to | 52 // See services discovered note above. |
| 42 // clean it ourselves. In this case, the services for a HeartRateDevice had | |
| 43 // been discovered in the previous test, since the state doesn't get cleaned | |
| 44 // it appears as if the services had been discovered for the device in this | |
| 45 // test. | |
| 46 // TODO(ortuno): split tests into different files. | |
| 47 // http://crbug.com/554240 | |
| 48 testRunner.setBluetoothMockDataSet(''); | 53 testRunner.setBluetoothMockDataSet(''); |
| 49 testRunner.setBluetoothMockDataSet('DelayedServicesDiscoveryAdapter'); | 54 testRunner.setBluetoothMockDataSet('DelayedServicesDiscoveryAdapter'); |
| 50 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) | 55 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) |
| 51 .then(device => device.connectGATT()) | 56 .then(device => device.connectGATT()) |
| 52 .then(gattServer => gattServer.getPrimaryService('heart_rate')) | 57 .then(gattServer => gattServer.getPrimaryService('heart_rate')) |
| 53 .then(service => { | 58 .then(service => { |
| 54 assert_equals(service.uuid, heart_rate.uuid); | 59 assert_equals(service.uuid, heart_rate.uuid); |
| 55 }); | 60 }); |
| 56 }, 'Request for service. Must return even when the services are not immediately
discovered'); | 61 }, 'Request for service. Must return even when the services are not immediately
discovered'); |
| 57 | 62 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 'UUID (lowercase hex characters e.g. ' + | 134 'UUID (lowercase hex characters e.g. ' + |
| 130 '\'00001234-0000-1000-8000-00805f9b34fb\'), ' + | 135 '\'00001234-0000-1000-8000-00805f9b34fb\'), ' + |
| 131 'or recognized standard name from ' + | 136 'or recognized standard name from ' + |
| 132 'https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx
' + | 137 'https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx
' + |
| 133 ' e.g. \'alert_notification\'.', | 138 ' e.g. \'alert_notification\'.', |
| 134 'SyntaxError'), | 139 'SyntaxError'), |
| 135 'Wrong Service name passed.'); | 140 'Wrong Service name passed.'); |
| 136 }); | 141 }); |
| 137 }, 'Wrong Service name. Reject with SyntaxError.'); | 142 }, 'Wrong Service name. Reject with SyntaxError.'); |
| 138 </script> | 143 </script> |
| OLD | NEW |