| 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="bluetooth-helpers.js"></script> | 4 <script src="bluetooth-helpers.js"></script> |
| 5 <script> | 5 <script> |
| 6 test(function(t) { assert_exists(window, "testRunner"); t.done(); }, | 6 test(function(t) { assert_exists(window, "testRunner"); t.done(); }, |
| 7 "window.testRunner is required for the following tests."); | 7 "window.testRunner is required for the following tests."); |
| 8 | 8 |
| 9 // Generic Access Service. | 9 // Generic Access Service. |
| 10 var serviceUUID = "00001800-0000-1000-8000-00805f9b34fb"; | 10 var serviceUUID = "00001800-0000-1000-8000-00805f9b34fb"; |
| 11 // Device Name Characteristic. Belongs to Generic Access. | 11 // Device Name Characteristic. Belongs to Generic Access. |
| 12 var includedCharacteristicUUID = "00002a00-0000-1000-8000-00805f9b34fb"; | 12 var includedCharacteristicUUID = "00002a00-0000-1000-8000-00805f9b34fb"; |
| 13 // Battery Level. Belongs to Battery Service. | 13 // Battery Level. Belongs to Battery Service. |
| 14 var nonIncludedCharacteristicUUID = "00002a19-0000-1000-8000-00805f9b34fb"; | 14 var nonIncludedCharacteristicUUID = "00002a19-0000-1000-8000-00805f9b34fb"; |
| 15 | 15 |
| 16 sequential_promise_test(function() { | 16 sequential_promise_test(function() { |
| 17 testRunner.setBluetoothMockDataSet('ConnectableDeviceAdapter'); | 17 testRunner.setBluetoothMockDataSet('ConnectableDeviceAdapter'); |
| 18 return navigator.bluetooth.requestDevice().then(function(device) { | 18 return navigator.bluetooth.requestDevice({ |
| 19 filters: [{services: [serviceUUID]}] |
| 20 }).then(function(device) { |
| 19 return device.connectGATT(); | 21 return device.connectGATT(); |
| 20 }).then(function(gattServer) { | 22 }).then(function(gattServer) { |
| 21 return gattServer.getPrimaryService(serviceUUID); | 23 return gattServer.getPrimaryService(serviceUUID); |
| 22 }).then(function(service) { | 24 }).then(function(service) { |
| 23 testRunner.setBluetoothMockDataSet('EmptyAdapter'); | 25 testRunner.setBluetoothMockDataSet('EmptyAdapter'); |
| 24 return service.getCharacteristic(includedCharacteristicUUID).then(function()
{ | 26 return service.getCharacteristic(includedCharacteristicUUID).then(function()
{ |
| 25 assert_unreached("Device went out of range, should fail."); | 27 assert_unreached("Device went out of range, should fail."); |
| 26 }, function(e) { | 28 }, function(e) { |
| 27 assert_equals(e.name, "NetworkError"); | 29 assert_equals(e.name, "NetworkError"); |
| 28 }); | 30 }); |
| 29 }); | 31 }); |
| 30 }, 'Device goes out of range. Reject with NetworkError.'); | 32 }, 'Device goes out of range. Reject with NetworkError.'); |
| 31 | 33 |
| 32 sequential_promise_test(function() { | 34 sequential_promise_test(function() { |
| 33 testRunner.setBluetoothMockDataSet('ConnectableDeviceAdapter'); | 35 testRunner.setBluetoothMockDataSet('ConnectableDeviceAdapter'); |
| 34 return navigator.bluetooth.requestDevice().then(function(device) { | 36 return navigator.bluetooth.requestDevice({ |
| 37 filters: [{services: [serviceUUID]}] |
| 38 }).then(function(device) { |
| 35 return device.connectGATT(); | 39 return device.connectGATT(); |
| 36 }).then(function(gattServer) { | 40 }).then(function(gattServer) { |
| 37 return gattServer.getPrimaryService(serviceUUID); | 41 return gattServer.getPrimaryService(serviceUUID); |
| 38 }).then(function(service) { | 42 }).then(function(service) { |
| 39 return service.getCharacteristic(nonIncludedCharacteristicUUID); | 43 return service.getCharacteristic(nonIncludedCharacteristicUUID); |
| 40 }).then(function(characteristic) { | 44 }).then(function(characteristic) { |
| 41 assert_equals(characteristic, null, | 45 assert_equals(characteristic, null, |
| 42 "Non existent characteristic should return null."); | 46 "Non existent characteristic should return null."); |
| 43 }); | 47 }); |
| 44 }, 'Request for wrong characteristic. Should return null.'); | 48 }, 'Request for wrong characteristic. Should return null.'); |
| 45 | 49 |
| 46 sequential_promise_test(function() { | 50 sequential_promise_test(function() { |
| 47 testRunner.setBluetoothMockDataSet('ConnectableDeviceAdapter'); | 51 testRunner.setBluetoothMockDataSet('ConnectableDeviceAdapter'); |
| 48 return navigator.bluetooth.requestDevice().then(function(device) { | 52 return navigator.bluetooth.requestDevice({ |
| 53 filters: [{services: [serviceUUID]}] |
| 54 }).then(function(device) { |
| 49 return device.connectGATT(); | 55 return device.connectGATT(); |
| 50 }).then(function(gattServer) { | 56 }).then(function(gattServer) { |
| 51 return gattServer.getPrimaryService(serviceUUID); | 57 return gattServer.getPrimaryService(serviceUUID); |
| 52 }).then(function(service) { | 58 }).then(function(service) { |
| 53 return service.getCharacteristic(includedCharacteristicUUID); | 59 return service.getCharacteristic(includedCharacteristicUUID); |
| 54 }).then(function(characteristic) { | 60 }).then(function(characteristic) { |
| 55 assert_equals(characteristic.uuid, includedCharacteristicUUID, | 61 assert_equals(characteristic.uuid, includedCharacteristicUUID, |
| 56 "Characteristic UUID should be the same as requested UUID."); | 62 "Characteristic UUID should be the same as requested UUID."); |
| 57 }); | 63 }); |
| 58 }, 'Request for characteristic. Should return right characteristic'); | 64 }, 'Request for characteristic. Should return right characteristic'); |
| 59 | 65 |
| 60 sequential_promise_test(function() { | 66 sequential_promise_test(function() { |
| 61 testRunner.setBluetoothMockDataSet('ConnectableDeviceAdapter'); | 67 testRunner.setBluetoothMockDataSet('ConnectableDeviceAdapter'); |
| 62 return navigator.bluetooth.requestDevice().then(function(device) { | 68 return navigator.bluetooth.requestDevice({ |
| 69 filters: [{services: [serviceUUID]}] |
| 70 }).then(function(device) { |
| 63 return device.connectGATT(); | 71 return device.connectGATT(); |
| 64 }).then(function(gattServer) { | 72 }).then(function(gattServer) { |
| 65 return gattServer.getPrimaryService(serviceUUID); | 73 return gattServer.getPrimaryService(serviceUUID); |
| 66 }).then(function(services) { | 74 }).then(function(services) { |
| 67 return Promise.all([services.getCharacteristic(includedCharacteristicUUID), | 75 return Promise.all([services.getCharacteristic(includedCharacteristicUUID), |
| 68 services.getCharacteristic(includedCharacteristicUUID)])
; | 76 services.getCharacteristic(includedCharacteristicUUID)])
; |
| 69 }).then(function(characteristics) { | 77 }).then(function(characteristics) { |
| 70 // TODO(ortuno): getCharacteristic should return the same object | 78 // TODO(ortuno): getCharacteristic should return the same object |
| 71 // if it was created earlier. | 79 // if it was created earlier. |
| 72 // https://crbug.com/495270 | 80 // https://crbug.com/495270 |
| 73 assert_not_equals(characteristics[0], characteristics[1], | 81 assert_not_equals(characteristics[0], characteristics[1], |
| 74 "Should return the same service as the first call."); | 82 "Should return the same service as the first call."); |
| 75 }); | 83 }); |
| 76 }, 'Calls to get the same characteristic should return the same object.'); | 84 }, 'Calls to get the same characteristic should return the same object.'); |
| 77 | 85 |
| 78 </script> | 86 </script> |
| OLD | NEW |